Is it possible to write something like:
data SomeData = SomeValue | (Integral a) => SomeConstructor a
And how exactly would one write this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is similar to Daniel Pratt’s answer, but the more typical approach is to leave off the type constraints on your data definition, like this:
Instead, you should put the
(Integral a)constraint on any functions that require it, which you’d have to do even if you added the constraint to the data definition too. Putting the constraint on the data definition buys you nothing, but forces you to carry around the constraint on all uses ofSomeData, even those that don’t care whatais at all. See Chapter 10 of Real World Haskell for more.