Clearly, I have some reading to do.

Thanks,

Michael

--- On Fri, 4/10/09, Ketil Malde <[email protected]> wrote:

From: Ketil Malde <[email protected]>
Subject: Re: [Haskell-cafe] Sequence differences
To: "michael rice" <[email protected]>
Cc: "haskell Cafe mailing list" <[email protected]>, "Joe Fredette" 
<[email protected]>
Date: Friday, April 10, 2009, 3:52 PM

michael rice <[email protected]> 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
thetan? 

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



      
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to