[Haskell-cafe] Over general types are too easy to make.

timothyhobbs at seznam.cz timothyhobbs at seznam.cz
Sun Sep 2 23:57:28 CEST 2012


Looks like I failed to reply all
---------- Původní zpráva ----------
Od: timothyhobbs at seznam.cz
Datum: 2. 9. 2012
Předmět: Re: Re: [Haskell-cafe] Over general types are too easy to make.
"
Care to link me to a code repository that doesn't have this problem? The 
only Haskell program that I have in my github that hasn't suffered this 
doesn't actually have any data declarations in it. Sure, if you're using 
data as a Boolean/Ternian replacement you won't have a trouble. But any 
multi record data constructor should be it's own type.

I was going to go try and find an example from GHC, but you said that you 
think this problem is domain specific, and it's true that all of my work has
had to do with code parsing/generation. So I went to look in darcs... Even 
with the shallow types of darcs we can still find examples of this problem:

http://hackage.haskell.org/packages/archive/darcs/2.8.1/doc/html/src/Darcs-
Match.html
(http://hackage.haskell.org/packages/archive/darcs/2.8.1/doc/html/src/Darcs-Match.html)

take a look at the function nonrangeMatcher, specifically OneTag, OneMatch, 
SeveralPatch... You can inspect the data declaration for DarcsFlag here 
http://hackage.haskell.org/packages/archive/darcs/2.8.1/doc/html/src/Darcs-
Flags.html ... Now ask yourself, what are the types for tagmatch and 
mymatch. They take Strings as arguments. Obviously they are typed 
incorrectly. tagmatch SHOULD have the type :: OneTag -> Matcher p. and 
mymatch SHOULD have the type PatchU -> Matcher p where data PatchU = 
OnePatchU OnePatch | SeveralPatchU SeveralPatch... But we can't just easily 
go and change the types. Because unfortunately GADT data declarations are 
not used here.

You've probably come across this many times. You just never realized it, 
because it's a case of GHC letting you do something you shouldn't be doing, 
rather than GHC stopping you from doing something you wish to.

Timothy

---------- Původní zpráva ----------
Od: Chris Smith <cdsmith at gmail.com>
Datum: 2. 9. 2012
Předmět: Re: [Haskell-cafe] Over general types are too easy to make.
"On Sun, Sep 2, 2012 at 9:40 AM, <timothyhobbs at seznam.cz> wrote:
> The thing is, that one ALWAYS wants to create a union of types, and not
> merely an ad-hock list of data declarations. So why does it take more code
> to do "the right thing(tm)" than to do "the wrong thing(r)"?

You've said this a few times, that you run into this constantly, or
even that everyone runs into this. But I don't think that's the case.
It's something that happens sometimes, yes, but if you're running
into this issue for every data type that you declare, that is
certainly NOT just normal in Haskell programming. So in that sense,
many of the answers you've gotten - to use a GADT, in particular -
might be great advice in the small subset of cases where average
Haskell programmers want more complex constraints on types; but it's
certainly not a good idea to do to every data type in your
application.

I don't have the answer for you about why this always happens to you,
but it's clear that there's something there - perhaps a stylistic
issue, or a domain-specific pattern, or something... - that's causing
you to face this a lot more frequently than others do. If I had to
take a guess, I'd say that you're breaking things down into fairly
complex monolithic parts, where a lot of Haskell programmers will have
a tendency to work with simpler types and break things down into
smaller pieces. But... who knows... I haven't seen the many cases
where this has happened to you.

-- 
Chris"
"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120902/0a7a5fa9/attachment.htm>


More information about the Haskell-Cafe mailing list