[Haskell-cafe] DatatypeContexts / alternative

Viktor Dukhovni ietf-dane at dukhovni.org
Tue Feb 23 18:33:53 UTC 2021


On Tue, Feb 23, 2021 at 06:21:23PM +0000, CASANOVA Juan wrote:

> I realized, with GADTs, it does assume Ord a, it's Ord b that fails. I
> can see how that cannot be derived from the context. Since Foo is only
> used for types with Ord, though, is there any way that I could let GHC
> know that this is going to be the case by definition.

This is NOT a GHC issue, this is a library issue.  To be a "Functor", a
data structure MUST accept values of any type.  This is essential in
Monads, where we, e.g., expect "return" to be able to return any value.

It seems you want to work with the endo-functors of a sub-category of
"Hask", so perhaps:

    https://hackage.haskell.org/package/constrained-category-0.1.0.0/docs/Data-Functor-Constrained.html

but then of course, you have to limit yourself to functions
that work within that category, so the standard "fmap" is
not available, standard Monads are not available, ...

-- 
    Viktor.


More information about the Haskell-Cafe mailing list