Re: [Haskell-cafe] Constraints on data-types, mis-feature?

2007-07-11 Thread Jonathan Cast
On Tuesday 10 July 2007, Jim Apple wrote:
> On 7/9/07, Jonathan Cast <[EMAIL PROTECTED]> wrote:
> > GADTs don't change anything (at least, not the last time I checked).
>
> GHC (in HEAD, at least) eliminates this wart for any datatype declared
> with GADT syntax.
>
> http://www.haskell.org/ghc/dist/current/docs/users_guide/data-type-extensio
>ns.html#gadt-style
>
> "Any data type that can be declared in standard Haskell-98 syntax can
> also be declared using GADT-style syntax. The choice is largely
> stylistic, but GADT-style declarations differ in one important
> respect: they treat class constraints on the data constructors
> differently. Specifically, if the constructor is given a type-class
> context, that context is made available by pattern matching."

Cool!  Looks like it does work in HEAD (although it does /not/ in 6.6.1).

Jonathan Cast
http://sourceforge.net/projects/fid-core
http://sourceforge.net/projects/fid-emacs
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Constraints on data-types, mis-feature?

2007-07-10 Thread Jonathan Cast
On Tuesday 10 July 2007, Jim Apple wrote:
> On 7/9/07, Jonathan Cast <[EMAIL PROTECTED]> wrote:
> > GADTs don't change anything (at least, not the last time I checked).
>
> GHC (in HEAD, at least) eliminates this wart for any datatype declared
> with GADT syntax.
>
> http://www.haskell.org/ghc/dist/current/docs/users_guide/data-type-extensio
>ns.html#gadt-style
>
> "Any data type that can be declared in standard Haskell-98 syntax can
> also be declared using GADT-style syntax. The choice is largely
> stylistic, but GADT-style declarations differ in one important
> respect: they treat class constraints on the data constructors
> differently. Specifically, if the constructor is given a type-class
> context, that context is made available by pattern matching."

I'll definitely check this out; I've been quite annoyed by this restriction in 
the past.

Jonathan Cast
http://sourceforge.net/projects/fid-core
http://sourceforge.net/projects/fid-emacs
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Constraints on data-types, mis-feature?

2007-07-10 Thread Jim Apple

On 7/9/07, Jonathan Cast <[EMAIL PROTECTED]> wrote:

GADTs don't change anything (at least, not the last time I checked).


GHC (in HEAD, at least) eliminates this wart for any datatype declared
with GADT syntax.

http://www.haskell.org/ghc/dist/current/docs/users_guide/data-type-extensions.html#gadt-style

"Any data type that can be declared in standard Haskell-98 syntax can
also be declared using GADT-style syntax. The choice is largely
stylistic, but GADT-style declarations differ in one important
respect: they treat class constraints on the data constructors
differently. Specifically, if the constructor is given a type-class
context, that context is made available by pattern matching."

Jim
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Constraints on data-types, mis-feature?

2007-07-09 Thread Jonathan Cast
On Monday 09 July 2007, Daniil Elovkov wrote:
> Hello
>
> In the archives of haskell-cafe I found a mention of constraints on
> datatypes as a mis-feature of Haskell. In particular, that they're not
> propagated well. Can someone elaborate on that?
>
> Also, are they still considered a mis-feature with the emergence of GADTs ?
>
> If I have
>
> data GADT a where
>...
>Alt :: (a -> b -> c) -> GADT a -> GADT b -> GADT c
>...
>
> and I want to constrain all a, b, c.
>
> Would it be better to expose all of them as type vars, rather than
> constrain in-place? It would lead to a rather verbose code.

GADTs don't change anything (at least, not the last time I checked).  If you 
say

class C a where
  ...

data GADT a where
  ...
  Alt :: (C a, C b, C c) => (a -> b -> c) -> GADT a -> GADT b -> GADT c
  ...

when you pattern match on Alt, the compiler finds the instances for C a and C 
b, but the constraint C c is ignored.  So constraints on data types work 
exactly the same way they always have, and the standard arguments against 
them all still work.  (Although now I think the status of this `feature' can 
be down-graded to wart: after all, if you say

newtype Id a = Id a
data GADT a where
  ...
  Alt :: (C a, C b, C c) => (a -> b -> c)
  -> GADT (Id a) -> GADT (Id b) -> GADT (Id c)
  ...

pattern-matching on Alt introduces all three constraints into the current 
context. . .)

Jonathan Cast
http://sourceforge.net/projects/fid-core
http://sourceforge.net/projects/fid-emacs
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Constraints on data-types, mis-feature?

2007-07-09 Thread Daniil Elovkov

Hello

In the archives of haskell-cafe I found a mention of constraints on
datatypes as a mis-feature of Haskell. In particular, that they're not
propagated well. Can someone elaborate on that?

Also, are they still considered a mis-feature with the emergence of GADTs ?

If I have

data GADT a where
  ...
  Alt :: (a -> b -> c) -> GADT a -> GADT b -> GADT c
  ...

and I want to constrain all a, b, c.

Would it be better to expose all of them as type vars, rather than
constrain in-place? It would lead to a rather verbose code.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe