<div dir="ltr"><div>You can do this, although you still need a datastructure that allows you to use the contained type:<br><br>{-# LANGUAGE GADTs #-}<br>{-# LANGUAGE StandaloneDeriving #-}<br>{-# LANGUAGE TypeSynonymInstances #-}<br>module Tutorial where<br><br>data Gender = Male | Female deriving (Show)<br><br>data Race = White | Black deriving (Show)<br><br>type Age = Int<br><br>data Answer a where<br> Answer :: RacistAgistSexist a => a -> Answer a<br><br>deriving instance Show w => Show (Answer w)<br><br>data GenderRaceAge<br> = Gender Gender<br> | Race Race<br> | Age Age<br><br>class RacistAgistSexist a where<br> genderRaceAge :: a -> GenderRaceAge<br>instance RacistAgistSexist Gender where<br> genderRaceAge = Gender<br>instance RacistAgistSexist Race where<br> genderRaceAge = Race<br>instance RacistAgistSexist Age where<br> genderRaceAge = Age<br><br></div>-- You can use genderRaceAge to get a GenderRaceAge out of the contained type if you don't know 'a'<br><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 15 May 2015 at 08:51, Tom Ellis <span dir="ltr"><<a href="mailto:tom-lists-haskell-cafe-2013@jaguarpaw.co.uk" target="_blank">tom-lists-haskell-cafe-2013@jaguarpaw.co.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Fri, May 15, 2015 at 01:47:49AM -0500, Cody Goodman wrote:<br>
> How can I create Answers of type Gender, Race, or Age?<br>
><br>
> These should be possible:<br>
><br>
> λ> Answer Male<br>
> λ> Answer White<br>
> λ> Answer Black<br>
> λ> Answer 28<br>
><br>
> Others such as using a string should not be possible:<br>
><br>
> λ> Answer "a string" -- should throw type error<br>
<br>
</span>It would probably help if you tell us why precisely you want this, and in<br>
particular why<br>
<br>
data Answer = AnswerGender Gender<br>
| AnswerRace Race<br>
| AnswerAge Int<br>
<br>
is not satisfactory.<br>
<span class="HOEnZb"><font color="#888888"><br>
Tom<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
</div></div></blockquote></div><br></div>