Are there documentation on constraints being types, how they can be declared/handled and what are the interests?
2012/2/7 Mikhail Vorozhtsov <mikhail.vorozht...@gmail.com> > On 02/06/2012 03:32 AM, Gábor Lehel wrote: > >> There's a common pattern in Haskell of writing: >> >> data E where E :: C a => a -> E >> also written >> data E = forall a. C a => E a >> >> I recently uploaded a package to Hackage which uses the new >> ConstraintKinds extension to factor this pattern out into an Exists >> type parameterized on the constraint, and also for an Existential type >> class which can encompass these kind of types: >> >> http://hackage.haskell.org/**package/exists<http://hackage.haskell.org/package/exists> >> >> My motivation was mostly to play with my new toys, if it turns out to >> be useful for anything that's a happy and unexpected bonus. >> >> Some interesting things I stumbled upon while writing it: >> >> [snip] > > - One of the advantages FunctionalDependencies has over TypeFamilies >> is that type signatures using them tend to be more readable and >> concise than ones which have to write out explicit equality >> constraints. For example, foo :: MonadState s m => s -> m () is nicer >> than foo :: (MonadState m, State m ~ s) => s -> m (). But with >> equality superclass constraints (as of GHC 7.2), it's possible to >> translate from TF-form to FD-form (but not the reverse, as far as I >> know): class (MonadStateTF m, s ~ State m) => MonadStateFDish s m; >> instance (MonadStateTF m, s ~ State m) => MonadStateFDish s m. >> > Even better, you can write > > type ExistentialWith c e = (Existential e, c ~ ConstraintOf e) > > instead of > > class (Existential e, c ~ ConstraintOf e) => ExistentialWith c e > instance (Existential e, c ~ ConstraintOf e) => ExistentialWith c e > > and drop UndecidableInstances. > > > > ______________________________**_________________ > Haskell-Cafe mailing list > Haskell-Cafe@haskell.org > http://www.haskell.org/**mailman/listinfo/haskell-cafe<http://www.haskell.org/mailman/listinfo/haskell-cafe> >
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe