You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To some extent, you can write Haskell functions that operate over refs without caring whether they're const or not. You just need the ref type to be an instance of IvoryRef. But the (!) and (~>) operators are more picky than that, requiring that both the argument ref and the resulting ref be instances of IvoryExpr. And that means that a const-generic function's class constraints need to include IvoryExpr instances for every struct, field, array, and array element type used in the function.
In discussing this with Trevor, the best option we came up with was to switch to capturing constness in a phantom type variable, something like so:
data Constness = Const | Mutable
data Ref' (c :: Constness) (s :: RefScope) (a :: Area *) = Ref' { getRef :: I.Expr }
type Ref = Ref' Mutable
type ConstRef = Ref' Const
(The two type aliases are to limit the number of changes required in existing code.)
A single instance for IvoryVar and IvoryExpr then covers all two varieties of Ref'. (I'm not sure whether IvoryType needs one or two instances.)
Code that doesn't care about constness (because it only derefs, it doesn't store) can take a Ref' c s area and just not constrain c.
The text was updated successfully, but these errors were encountered:
To some extent, you can write Haskell functions that operate over refs without caring whether they're const or not. You just need the ref type to be an instance of
IvoryRef
. But the(!)
and(~>)
operators are more picky than that, requiring that both the argument ref and the resulting ref be instances ofIvoryExpr
. And that means that a const-generic function's class constraints need to includeIvoryExpr
instances for every struct, field, array, and array element type used in the function.In discussing this with Trevor, the best option we came up with was to switch to capturing constness in a phantom type variable, something like so:
(The two type aliases are to limit the number of changes required in existing code.)
A single instance for
IvoryVar
andIvoryExpr
then covers all two varieties ofRef'
. (I'm not sure whetherIvoryType
needs one or two instances.)Code that doesn't care about constness (because it only derefs, it doesn't store) can take a
Ref' c s area
and just not constrainc
.The text was updated successfully, but these errors were encountered: