Re: [Haskell-beginners] a bunch o' questions
Leaf and Branch are type-constructors, and "Tree a" is a parametrized type. Constructor is what you actually use to construct trees, but the type (Tree a) you use to annotate values. Like in
let t = Branch (Leaf 1) (Leaf 2) :: Tree Int you constuct a tree with two leaves, and after two colons say, that the type of the tree is Tree Int
Markus
Leaf and Branch are type-constructors, and "Tree a" is a parametrized type.
I think this is wrong. Leaf and Branch are *data* constructors, and Tree is, indeed, a type constructor.
From http://www.haskell.org/all_about_monads/html/meet.html :
Type constructors To understand monads in Haskell, you need to be comfortable dealing with type constructors. A type constructor is a parameterized type definition used with polymorphic types. By supplying a type constructor with one or more concrete types, you can construct a new concrete type in Haskell. In the definition of Maybe: data Maybe a = Nothing | Just a Maybe is a type constructor and Nothing and Just are data constructors. You can construct a data value by applying the Just data constructor to a value: country = Just "China" In the same way, you can construct a type by applying the Maybe type constructor to a type: lookupAge :: DB -> String -> Maybe Int Best regards, Ricardo Carnieri
Yep, your're right! On Thu, Jul 1, 2010 at 7:49 PM, Ricardo Carnieri <carnieri@gmail.com> wrote:
Leaf and Branch are type-constructors, and "Tree a" is a parametrized type.
I think this is wrong. Leaf and Branch are *data* constructors, and Tree is, indeed, a type constructor.
participants (2)
-
Markus Läll -
Ricardo Carnieri