Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ease generalizing over const or mutable refs #26

Open
jameysharp opened this issue Jan 27, 2015 · 1 comment
Open

Ease generalizing over const or mutable refs #26

jameysharp opened this issue Jan 27, 2015 · 1 comment

Comments

@jameysharp
Copy link
Contributor

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.

@pchickey
Copy link
Contributor

Great idea, great plan for implementing it. I see no reason not to do this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants