[Haskell-cafe] Can I specify the a in a phantom type to be limited to a sum type?

Tom Ellis tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk
Fri May 15 06:51:52 UTC 2015


On Fri, May 15, 2015 at 01:47:49AM -0500, Cody Goodman wrote:
> How can I create Answers of type Gender, Race, or Age?
> 
> These should be possible:
> 
> λ> Answer Male
> λ> Answer White
> λ> Answer Black
> λ> Answer 28
> 
> Others such as using a string should not be possible:
> 
> λ> Answer "a string" -- should throw type error

It would probably help if you tell us why precisely you want this, and in
particular why

data Answer = AnswerGender Gender
            | AnswerRace   Race
            | AnswerAge    Int

is not satisfactory.

Tom



More information about the Haskell-Cafe mailing list