[Haskell-cafe] Re: RLE in Haskell: why does the type variable get instantiated?

Brandon S. Allbery KF8NH allbery at ece.cmu.edu
Tue Jul 31 08:09:58 EDT 2007


On Jul 31, 2007, at 6:00 , apfelmus wrote:

> Chris Eidhof wrote:
>> When binding the function composition to a variable, the type
>> suddenly changes.
>>
>> Prelude Control.Arrow List> :t map (length &&& head) . group
>> map (length &&& head) . group :: (Eq a) => [a] -> [(Int, a)]
>> Prelude Control.Arrow List> let encode = map (length &&& head) .  
>> group
>> Prelude Control.Arrow List> :t encode
>> encode :: [Integer] -> [(Int, Integer)]
>
> In short, you have to supply a type signature
>
>   encode :: (Eq a) => [a] -> [(Int, a)]
>   encode = map (length &&& head) . group

Note that you can do this at the GHCi prompt like this:

 > let encode :: (Eq a) => [a] -> [(Int,a)]; encode = map (length &&&  
head) . group

since you can't use multi-line declarations from the prompt.

-- 
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery at kf8nh.com
system administrator [openafs,heimdal,too many hats] allbery at ece.cmu.edu
electrical and computer engineering, carnegie mellon university    KF8NH




More information about the Haskell-Cafe mailing list