<html><body bgcolor="#FFFFFF"><div>&gt;&nbsp;<span class="Apple-style-span" style="-webkit-tap-highlight-color: rgba(26, 26, 26, 0.296875); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469); font-size: 15px; font-family: arial, helvetica, sans-serif; ">For example, I can ask a question which requires a Double as an&nbsp;<br>answer and another which requires an Int as an answer:</span></div><div><font class="Apple-style-span" face="arial, helvetica, sans-serif" size="4"><span class="Apple-style-span" style="font-size: 15px; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469);"><br></span></font></div><div><font class="Apple-style-span" face="arial, helvetica, sans-serif" size="4"><span class="Apple-style-span" style="font-size: 15px; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469);">Might this be easier if you made all the answers strings? If you need to permit things like 0.5 vs .5 you could instead use a String-&gt;String normalisation function which could vary with the "type" of the answer but not affect the data type of the question.</span></font></div><div><font class="Apple-style-span" face="arial, helvetica, sans-serif" size="4"><span class="Apple-style-span" style="font-size: 15px; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469);"><br></span></font></div><div><font class="Apple-style-span" face="arial, helvetica, sans-serif" size="4"><span class="Apple-style-span" style="font-size: 15px; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.292969); -webkit-composition-fill-color: rgba(175, 192, 227, 0.230469); -webkit-composition-frame-color: rgba(77, 128, 180, 0.230469);">It would also be easier to use strings if you wanted to store the questions in a database or load from a file. &nbsp;<br></span></font><br>Peter</div><div><br>On 24 Nov 2011, at 09:32, Alia &lt;<a href="mailto:alia_khouri@yahoo.com">alia_khouri@yahoo.com</a>&gt; wrote:<br><br></div><div></div><blockquote type="cite"><div><div style="color:#000; background-color:#fff; font-family:arial, helvetica, sans-serif;font-size:10pt"><div>Hi folks,<br><br>As the code (from my prior post) is not so relevant to the issue<br>at hand, it was quite reasonably suggested that I should simplify my<br>question somewhat. So here goes:<br><br>In my model, I have a Question record type, which has a type parameter<br>to take into account that answers can be evaluated to different types.<br>For example, I can ask a question which requires a Double as an <br>answer and another which requires an Int as an answer:<br><br>data Question a = Question {text:: String, answer:: Maybe a}<br><br>This question type is wrapped/boxed in another type to allow the <br>different questions to referenced in a list. Hence,<br><br>data Question' = QuestionS (Question String)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | QuestionI (Question
 Int)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | QuestionD (Question Double)<br><br>and I can now store the questions as follows:<br><br>questions = [ QuestionI {text="What's 1+1?", answer=Maybe 2}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; , QuestionD {text="What's 1.0+1.5?", answer=Maybe 2.5}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ]<br><br>Now to extract Question a from Question' I would have liked to write <br>the following:<br><br>extract :: Question' -&gt; Question a<br>extract q = case q of<br>&nbsp;&nbsp;&nbsp; QuestionS x -&gt; extractQString q<br>&nbsp;&nbsp;&nbsp; QuestionI x -&gt; extractQInt q<br>&nbsp;&nbsp;&nbsp; QuestionD x -&gt; extractQDouble q<br><br>but instead, I had to produce the following instead:<br><br>extractQString :: Question' -&gt; Question String<br>extractQString (QuestionS q) = q<br><br>extractQInt :: Question' -&gt;
 Question Int<br>extractQInt (QuestionI q) = q<br><br>extractQDouble :: Question' -&gt; Question Double<br>extractQDouble (QuestionD q) = q<br><br>From what I understand so far, that specialized extraction or unboxing<br>functions are the way to go unless one uses language extensions like<br>GADTs which can be conceptually more complicated. Is this indeed the case,<br>or are there other ways to achieve generalized type unboxing while<br>remaining within the Haskell98 specification?<br><br>Best,<br><br>Alia <br>&nbsp;</div></div></div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>Beginners mailing list</span><br><span><a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a></span><br><span><a href="http://www.haskell.org/mailman/listinfo/beginners">http://www.haskell.org/mailman/listinfo/beginners</a></span><br></div></blockquote></body></html>