Hi haskellers,<br><br>I have a datatype of this sort:<br><br>data Type = Status<br>          | Message<br>          | Warning<br>          | Error  <br>          | StepIn<br>          | StepOut deriving (Eq, Show)<br><br>and (at this moment) two fabric-like functions:<br>
<br>makeType :: String -&gt; Type<br>makeType c = case c of<br>               &quot;-$-&quot;       -&gt; Status<br>               &quot;-M-&quot;       -&gt; Message<br>               &quot;-W-&quot;       -&gt; Warning<br>
               &quot;-E-&quot;       -&gt; Error<br>               &quot;-&gt;&gt;&quot;       -&gt; StepIn<br>               &quot;&lt;&lt;-&quot;       -&gt; StepOut<br>               otherwise   -&gt; error &quot;Uknown Message Type&quot;<br>
<br>deduceType :: Integer -&gt; Type<br>deduceType n = case n of<br>                 240       -&gt; Status<br>                 64        -&gt; Message<br>                 32        -&gt; Warning<br>                 8         -&gt; StepOut<br>
                 4         -&gt; StepIn<br>                 2         -&gt; Error<br>                 otherwise -&gt; error &quot;Unknown Message Type&quot;<br><br>how can I avoid boilerplate code at this stage? The thing that I really need is some n-type constructor, kind of a fabric for a variety of types with the possibility to add them on the fly (I have simple Integer and String here, but they could be much more sophisticated). I don&#39;t need the possibility to unpack the original value (e.g. &quot;-$-&quot; or 240) once the Type is created - in this case I can always have some sort of mapping to deduce it at any moment, so it will be redundant to carry it through the code explicitly<br>
<br>The example is rather short and simple, but I have some more places in code, where the same problem is observed. Is there any generic solution? Thanks in advance<br clear="all"><br>-- <br>Regards, Paul Sujkov<br>