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

auto-derive Div (a * x) a ~ x #24

Open
tscholak opened this issue Sep 28, 2019 · 1 comment
Open

auto-derive Div (a * x) a ~ x #24

tscholak opened this issue Sep 28, 2019 · 1 comment

Comments

@tscholak
Copy link

tscholak commented Sep 28, 2019

I'd like to define the following:

test :: (1 <= a) => Proxy (Div (n * a) a) -> Proxy n
test = id

However, with -fplugin GHC.TypeLits.Normalise (0.3.1), -fplugin GHC.TypeLits.KnownNat.Solver (0.7), -fplugin GHC.TypeLits.Extra.Solver (0.7),and -fconstraint-solver-iterations=0, ghc 8.6.5 won't have this and complains:

    • Could not deduce: Div (n * a) a ~ n
      from the context: 1 <= a

Is there any way to achieve this?

PS: I can define this:

foo :: forall x n a . (x ~ (n * a)) => Proxy n -> Proxy a -> ()
foo = const . const ()

but this doesn't give me what I need downstream.

@christiaanb
Copy link
Member

christiaanb commented Sep 28, 2019

You can extend this function to get the behavior you want:

mergeDiv :: ExtraOp -> ExtraOp -> Maybe ExtraOp

Extend

with a constructor for multiplication.

And create the mult constructor here:

normaliseNat :: ExtraDefs -> Type -> MaybeT TcPluginM ExtraOp

And add an extra field for the multiplication tycon here:

The rest should follow for solving all the type errors.

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

No branches or pull requests

2 participants