gust
gust

Reputation: 945

Parametrize return type based on concrete type of typeclass

Consider I have the following template for two typeclasses:

data TheoryParseErr = TheoryParseErr deriving (Show)

class Theory t where
    applySemantics
        :: (Functor f, TheorySymbol s)
        => t
        -> f a
        -> f (Either TheoryParseErr s)

class TheorySymbol a where
  readT  :: String -> Either TheoryParseErr a

I want to have multiple instances of these typeclasses. For instance, the Uninterpreted Functions:

data UfTheory = UfTheory deriving (Show, Eq)

instance Theory UfTheory where
  applySemantics _ = fmap readT

data UfSymbol = Uninterpreted String deriving (Show)

instance TheorySymbol UfSymbol where
    readT s = Right $ Uninterpreted s

However, this is not possible, because the function

applySemantics:: (Foldable f, TheorySymbol s) => t -> f a -> f (Either TheoryParseErr s)

is giving types of forall a. a and forall TheorySymbol s. s.

Ideally, I want to control which types a and s are for my choice of type t.

Is this possible?

Upvotes: 0

Views: 149

Answers (0)

Related Questions