Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  More Deserialization Woes (Stephen Tetley)
   2.  a bunch o' questions (Michael Mossey)
   3. Re:  a bunch o' questions (Markus L?ll)
   4. Re:  a bunch o' questions (Ricardo Carnieri)
   5. Re:  a bunch o' questions (Markus L?ll)


----------------------------------------------------------------------

Message: 1
Date: Thu, 1 Jul 2010 12:17:51 +0100
From: Stephen Tetley <[email protected]>
Subject: Re: [Haskell-beginners] More Deserialization Woes
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

Hi

As Benjamin Edwards says you want to be in the IO monad as you are
using a file handle

Something like this - note the last two lines have changed a bit to
accommodate the computation being in the IO monad rather than pure, if
you have very large input data you might need to put this in tail
recursive form.

readNames :: Int -> Handle -> IO [String]
readNames 0 _ = return []  -- add a return, to lift the answer into IO
readNames n h = do
  length <- fmap (fromIntegral . runGet getWord32be) $ L.hGet h 4
  name <- L.hGet h length
  rest <- readNames (n-1) h
  return ((UTF.toString name) : rest)


------------------------------

Message: 2
Date: Thu, 01 Jul 2010 09:32:35 -0700
From: Michael Mossey <[email protected]>
Subject: [Haskell-beginners] a bunch o' questions
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

I have some questions about terminology re types and type constructors.

If we have

data Tree a = Branch (Tree a) (Tree a)
             | Leaf a

Then is 'Tree' a type constructor?
Is it correct to say:
   - 'Tree' is parameterized by one type, a
   - 'Tree a' is a type

Regarding (->):

   - Is (->) a type constructor parameterized by two types?
   - Is (->) an operator? If so, it is the only operator that is also a type
     constructor?

Thanks,
Mike


------------------------------

Message: 3
Date: Thu, 1 Jul 2010 19:43:04 +0300
From: Markus L?ll <[email protected]>
Subject: Re: [Haskell-beginners] a bunch o' questions
To: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

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


------------------------------

Message: 4
Date: Thu, 1 Jul 2010 13:49:59 -0300
From: Ricardo Carnieri <[email protected]>
Subject: Re: [Haskell-beginners] a bunch o' questions
To: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

> 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


------------------------------

Message: 5
Date: Thu, 1 Jul 2010 19:53:53 +0300
From: Markus L?ll <[email protected]>
Subject: Re: [Haskell-beginners] a bunch o' questions
To: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

Yep, your're right!

On Thu, Jul 1, 2010 at 7:49 PM, Ricardo Carnieri <[email protected]> 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.


------------------------------

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 25, Issue 2
****************************************

Reply via email to