Re: [Haskell-cafe] Basic question....
----- Ursprüngliche Nachricht ----- Von: "rodrigo.bonifacio" <rodrigo.bonifacio@uol.com.br> Datum: Freitag, August 17, 2007 3:11 pm Betreff: [Haskell-cafe] Basic question....
Hi all.
I want to create the following polymorphic type (EnvItem) that we can apply two functions (envKey and envValue). I tried the following:
type Key = String
data EnvItem a = EnvItem (Key, a)
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]
I think this is a very basic problem, but I don't know what is wrong.
You are simply missing some brackets:
envKey :: EnvItem (Key, a) -> String envKey (EnvItem (key, value)) = key
envValue :: EnvValue(Key, a) -> a envValue (EnvItem (key, value)) = value
Ciao, Janis.
Not only does you lack some parens around your patterns, your function types are wrong : type Key = String data EnvItem a = EnvItem (Key, a) envKey :: EnvItem a -> String envKey (EnvItem (key, value)) = key envValue :: EnvItem a -> a envValue (EnvItem (key, value)) = value -- Jedaï
"Chaddaï Fouché" <chaddai.fouche@gmail.com> writes:
Not only does you lack some parens around your patterns, your function types are wrong :
type Key = String
data EnvItem a = EnvItem (Key, a)
envKey :: EnvItem a -> String envKey (EnvItem (key, value)) = key
envValue :: EnvItem a -> a envValue (EnvItem (key, value)) = value
Why not
data EnvItem a = EnvItem {key:: Key, value:: a}
? -- Jón Fairbairn Jon.Fairbairn@cl.cam.ac.uk
17 Aug 2007 14:44:28 +0100, Jon Fairbairn <jon.fairbairn@cl.cam.ac.uk>:
Why not
data EnvItem a = EnvItem {key:: Key, value:: a}
It's the real solution, but I feel it was worthwhile to underscore the other mistakes (often encountered by the newbies) in types and parameters. -- Jedaï
participants (3)
-
Chaddaï Fouché -
Janis Voigtlaender -
Jon Fairbairn