[Haskell-cafe] Basic question....

Brandon S. Allbery KF8NH allbery at ece.cmu.edu
Fri Aug 17 09:15:00 EDT 2007


On Aug 17, 2007, at 9:11 , rodrigo.bonifacio wrote:

>> envKey :: EnvItem (Key, a) -> String
>> envKey EnvItem (key, value) = key
>
>> envValue :: EnvValue(Key, a) -> a
>> envValue EnvItem (key, value) = value
>
> But this is resulting in the error: [Constructor "EnvItem" must  
> have exactly 1 argument in pattern]

You need to parenthesize the constructor.

envValue (EnvItem (_,value)) = value

(The _ indicates that you're not using that item, rather than giving  
it a name that won't be used.)

Why do you need to do this?  Because you can pass functions around,  
and a constructor is a function.  But your type says you don't want a  
bare function there, so the compiler complains.

-- 
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