[Haskell-cafe] Re: Typeclass question
Andrew Wagner wagner.andrew at gmail.com writes: I'm sure there's a way to do this, but it's escaping me at present. I want to do something like this: data Foo = Bar a = Foo a Bool ... That is, I want to create a new type, Foo, whose constructor takes both a Boolean and a value of a type of class Bar. Sometimes it's enough to declare data Foo a = Foo a Bool and to put the 'Bar a =' context onto the functions and instances that involve Foo. For example, in Chris Okasaki's book Purely Functional Data Structures, the h in data BootstrapHeap h a = ... is always meant to satisfy 'Heap h =', but this is ensured by putting the context at all the points where a BootstrapHeap is created, and not exporting BootstrapHeap's data constructors. Regards, Tom ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Typeclass question
Tom Pledger wrote: Andrew Wagner wagner.andrew at gmail.com writes: I'm sure there's a way to do this, but it's escaping me at present. I want to do something like this: data Foo = Bar a = Foo a Bool ... That is, I want to create a new type, Foo, whose constructor takes both a Boolean and a value of a type of class Bar. Sometimes it's enough to declare data Foo a = Foo a Bool and to put the 'Bar a =' context onto the functions and instances that involve Foo. Although, if you really want to omit the `a` from the type, you can use the ExistentialQuantification extension or GADTs to do something like: -- with ExistentialQuantification data Foo = forall a . Bar a = Foo a Bool -- with GADTs data Foo where forall a . Bar a = Foo a Bool I haven't used either extension in a few months though, so I may have gotten the syntax wrong. You can look them up to be sure. - Jake ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Typeclass question
Stefan O'Rear wrote: [...] Unfortunately, it turns out that allowing foralls inside function arguments makes typechecking much harder, in general impossible. Just a tiny correction: AFAIK, it is type /inference/ which becomes undecidable in the presence of higher rank types -- checking works just fine (it could be true that it's harder, though). Cheers Ben ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe