Constraint on data type

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Constraint on data type

Vlatko Basic
Hi Cafe,

I have these typeclasses defined:

     class UA a where ...
     class RA a where ...

and this data definition

     data (UA u, RA r) => AD u r = AD { ... }

I have another data definition

     data ACT aur c = ACT { x :: aur, ... }

but the type 'aur' should be restricted to (AD u r) only.
(I would like to keep 'aur' as 1 parameter, not as
     data ACT u r c = ACT { x :: AD u r, ... } )


How can such constraint be defined?


Best regards,

vlatko
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Constraint on data type

Albert Y. C. Lai
On 14-01-20 06:48 AM, Vlatko Basic wrote:
> I have another data definition
>
>      data ACT aur c = ACT { x :: aur, ... }
>
> but the type 'aur' should be restricted to (AD u r) only.
> (I would like to keep 'aur' as 1 parameter, not as

It is unnecessary to enforce your rule at the data declaration. It is
sufficient and necessary to enforce it at relevant functions and values.
For example:

transform :: (UA u, RA r) => ACT (AD u r) Int -> ACT (AD u r) Bool

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe