[Haskell-cafe] Sequence differences

michael rice nowgate at yahoo.com
Fri Apr 10 16:09:27 EDT 2009

Clearly, I have some reading to do.



--- On Fri, 4/10/09, Ketil Malde <ketil at malde.org> wrote:

From: Ketil Malde <ketil at malde.org>
Subject: Re: [Haskell-cafe] Sequence differences
To: "michael rice" <nowgate at yahoo.com>
Cc: "haskell Cafe mailing list" <haskell-cafe at haskell.org>, "Joe Fredette" <jfredett at gmail.com>
Date: Friday, April 10, 2009, 3:52 PM

michael rice <nowgate at yahoo.com> writes:

> map :: (a -> b) -> [a] -> [b]    <==  I'm assuming this is correct

This is the type of 'map', yes.  Btw, ou can check types in GHCi with the
:i command.

> s f ls 
> seems much like
> map f ls
> but instead looks like   
> s :: (a -> a -> a) -> [a] -> [a]

If you look at the definition:

>> s f [] = []
>> s f [x] = [x]
>> s f l = [ a f b | (a,b) <- zip (init l) (tail l)]

You'll notice that the second clause, namely

   s f [x] = [x]

produces the second parameter [x] (of type [a]) as its output, and
thus the types must be the same as well. 

Also (assuming it is 'f a b' and not 'a f b' in the list
comprehension), f is applied to two parameters, so it'll have to be
of type (x -> y -> z), and since the two input parameters come from
the originating list, x and y must be the same as a, and since we have
seen the result list also has the same type, z must be the same as a,
too.  Thus f must have type (a -> a -> a).  Unclear? Clear? Operating

If I haven't seen further, it is by standing in the footprints of giants

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090410/a434ed41/attachment-0001.htm

More information about the Haskell-Cafe mailing list