To create a type class that accepts natures like Z, (SZ), (S (SZ)), etc., you can simply declare instances recursively as such:
data Z data S a class Type a instance Type Z instance Type (S a)
Is it possible to instantiate a type class based on level predicates? For example, I want to say:
{-
Where :+: is the addition of a type level, and == is the level correspondence at the level from Data.Type.Equality , therefore instances are created only for pairs of nats that are up to 8.
Are notations like this available in Haskell? If not, how would this be done?
Edit: This post was inspired by a Haskell Wiki article on intelligent constructors declaring an InBounds class type to statically verify that the phantom type argument passed to the intelligent constructor was in a certain Nat s range, the intelligent constructor was:
resistor :: InBounds size => size -> Resistor size resistor _ = Resistor
Trying to do something similar in my example (after using leftaroundabout answer) gives me an error:
construct :: (Type ab) => a -> b -> MyType ab construct _ _ = MyType >>> Expected a type, but a has kind Natβ¦
The Haskell file wiki example works because it does not use DataKinds, is it possible to pass a type of Nat type to a level value function?
source share