<br><div><span class="gmail_quote">On 8/17/07, <b class="gmail_sendername">rodrigo.bonifacio</b> &lt;<a href="mailto:rodrigo.bonifacio@uol.com.br">rodrigo.bonifacio@uol.com.br</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi all.<br><br>I want to create the following polymorphic type (EnvItem) that we can apply two functions (envKey and envValue). I tried the following:<br><br>&gt; type Key = String<br><br>&gt; data EnvItem a = EnvItem (Key, a)
<br><br>&gt; envKey :: EnvItem (Key, a) -&gt; String<br>&gt; envKey EnvItem (key, value) = key<br><br>&gt; envValue :: EnvValue(Key, a) -&gt; a<br>&gt; envValue EnvItem (key, value) = value<br><br>But this is resulting in the error: [Constructor &quot;EnvItem&quot; must have exactly 1 argument in pattern]
<br><br>I think this is a very basic problem, but I don&#39;t know what is wrong.<br><br>Regards,<br><br>Rodrigo.</blockquote><div><br>By the way, I would suggest giving the data type and constructor different names:<br><br>
data EnvItem a = EI (Key, a)<br><br>You do often see people use the same name for both, but that can be confusing since they are really two different things.&nbsp; The envKey function (for example) would now be written like this:
<br><br>envKey :: EnvItem a -&gt; Key <br></div>envKey (EI (key, _)) = key<br><br>The difference between the parameter type (EnvItem a) and a pattern to match the shape of such a value (EI (key, _)) is now much clearer: whatever is on the left side of the data declaration is the type, and goes in type signatures; whatever is on the right side describes the shape of values of that type, and is used to construct or deconstruct (through pattern-matching) such values.&nbsp; This way it is much harder to make mistakes like (for example) putting EnvItem (Key, a) in the type signature instead of EnvItem a.
<br><br>-Brent<br></div>