[Haskell-cafe] newbie type signature question
Brian Hulley
brianh at metamilk.com
Fri Jun 9 19:05:25 EDT 2006
Brock Peabody wrote:
>> Brian Hulley wrote:
>
>> There was a post a while back (unfortunately I can't seem to locate
>> it) where someone posted a link to some guidelines on haskell coding
>> style where
>> one guideline was never to use contexts in data declarations.
>
> I would love to see that guideline. What is the correct way to
> express a constraint for a data declaration if this way is wrong?
It is at
http://www.informatik.uni-bremen.de/agbkb/forschung/formal_methods/CoFI/hets/src-distribution/daily/HetCATS/docs/Programming-Guidelines.txt
in the section under "Types":
"Don't put class constraints on a data type,
constraints belong only to the functions
that manipulate the data."
So according to this guideline you're not supposed to think of associating
contraints with data: constraints are only relevant for functions which
manipulate the data, therefore (if you agree with this view) the very idea
of associating constraints with data is wrong.
It is possible that this feature was added to the language for the benefit
of people who prefer not to use explicit type signatures but afaiu this goes
against best practice where everything should always have an explicit
signature to make code easy to understand and facilitate debugging of type
errors.
Of course this does not apply to the completely different use of constraints
when defining existential types.
Regards, Brian.
--
Logic empowers us and Love gives us purpose.
Yet still phantoms restless for eras long past,
congealed in the present in unthought forms,
strive mightily unseen to destroy us.
http://www.metamilk.com
More information about the Haskell-Cafe
mailing list