"Free" type variables associated with functional dependencies in type synonyms
Given the class
class MonadSignal m sigs | m -> sigs where ...
and class
class CanSignal sigs sigs' where ...
I want to define a type synonym like this
type MonadSignal' sigs m = (MonadSignal m sigs', CanSignal sigs sigs')
Here the variable is sigs'not mentioned in the header of the type synonym MonadSignal', but there it is just for connecting the first and second restrictions, and it is uniquely determined m, which is mentioned in the header.
Usually I think I can do forallit on RHS, but since this is just a synonym Constraint, there is no real body for a variable to appear.
Is there anything you can do here? (in addition to put the variable in the head and give the wrong impression when the synonym is actually used, that it is the actual "variable")
, - .
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE TypeFamilies #-}
module TypeFamily where
class Monad m => MonadSignal m where
type Sig m :: *
make :: m sig
class CanSignal sigs sigs' where
type MonadSignal' sigs m = (MonadSignal m, CanSignal sigs (Sig m))
, , multiparameter , , , " ".
, , , (. , ). , , MonadSignal' , , . , Dict, .
, ,
class MonadSignal sigs m | m -> sigs
, GeneralizedNewtypeDeriving .
, fundeps :
class (sigs ~ Sigs m) => MonadSignal sigs m where
type Sigs m :: * -- Or appropriate kind
...
type MonadSignal' sigs m = (MonadSignal (Sigs m) m, CanSignal sigs (Sigs m))
:
class MonadSignal' sigs (m :: * -> *)
instance (MonadSignal m sigs', CanSignal sigs sigs') => MonadSignal' sigs m
In a class instance, a type variable sigs'does not appear in the class header, so you need to use {-# LANGUAGE UndecidableInstances #-}it to work. Although I do not believe that this class can actually lead to termination.