Dear Haskell experts,
I working on a large Haskell project on Model Based Testing (see https://github.com/TorXakis/TorXakis)
and I would like to get feedback on a design issue I have related to extension and parameterized classes.
I will describe a small simplified example to illustrate the issue
and I appreciate any feedback.
I have a class that extends another class as follows:
class Base a => Extend a where
-- | Constructor from Base
fromBase :: Base b => b -> a
I can define an instance of Extend that hides the Base implementation as follows:
{-# LANGUAGE ExistentialQuantification #-}
data BaseHidden = forall a . Base a =>
BaseHidden { _base :: a
, ... -- additional extension info
}
instance Extend BaseHidden where
fromBase b = BaseHidden b ... -- additional extension initialization
I can define a parameterized data class of which the parameter is the type of the Base class as follows:
data BaseExpose a = BaseExpose { _base :: a
, ... -- additional extension info
}
With this parameterized data class, I can make the following fromBase' function
fromBase' :: Base a => a -> BaseExpose a
fromBase' a = BaseExpose a ... -- additional extension initialization
My question is can I make BaseExpose an instance of Extend?
I am aware that the signature of fromBase states that for all 'b' of Base
an Extend of type 'a' must be able to be made.
Yet, in my case 'a' is a parameterized class 'BaseExpose x' and
since the type of Extend is provided (it is a constructor)
I think it is acceptable that 'BaseExpose b' is returned as type.
I have looked at some extensions, such as InstanceSigs, yet I found no solution.
Does anybody on this mailing list have an answer or solution for me?
Also experience in a large project related to maintenance for the two alternatives (hiding or exposing types) is appreciated!
Thanks in advance,
Pierre van de Laar