**[Q] Constraint Kinds, ambiguous type variables**

Hi, I'm curious as to how tuples of Constraint Kinds work. The specific problem I'm trying to solve is as follows:

`data X a = X a deriving (Eq, Ord, Read, Show) class IsLit a where isLit :: a -> X a instance IsLit Int where isLit = X instance IsLit String where isLit = X f :: (IsLit a, Num a) => a -> X a f = isLit . (+1) x = f 1 `

This results in a `No instance for Num a`

compile error.

Two questions:

- Why doesn't the compiler see that the only intersection of the set of instances for the two type classes is
`Int`

- Is it possible to create a constraint kind/type that restricts the set of types. (I imagine something of the form
`a ~ Or (Int, Or (String, Bool))`

Submitted July 16, 2017 at 08:18PM by joshcc4

via reddit http://ift.tt/2tgkCLV

Advertisements