[Q] Constraint Kinds, ambiguous type variables

[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


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s