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

Get really fancy with inference #15

Closed
treeowl opened this issue Jul 24, 2019 · 0 comments · Fixed by #16
Closed

Get really fancy with inference #15

treeowl opened this issue Jul 24, 2019 · 0 comments · Fixed by #16

Comments

@treeowl
Copy link
Contributor

treeowl commented Jul 24, 2019

I realized that even the Newtype class only gets us to an approximation of the platonic ideal. In particular, my understanding is that n and n' are really supposed to be the same newtype, perhaps with different type arguments. Can we express that? I bet we can, with ConstraintKinds!

class (Sim n n', Sim n' n) => Similar n n'
instance (Sim n n', Sim n' n) => Similar n n'

type family GetArg (x :: j) :: k where
  GetArg (_ a) = a

type family GetFun (x :: j) :: k where
  GetArg (f _) = f

type family Sim (n :: k) (n' :: k) :: Constraint where
  Sim (f a) n' = (Sim f (getFun n'), n' ~ getFun n' (GetArg n'))
  Sim f g = f ~ g

I haven't tried compiling this, So I don't know if it works or even if it can be made to work, but I think it's a pretty interesting possibility.

treeowl added a commit to treeowl/coercible-utils that referenced this issue Jul 25, 2019
The original concept of this API is to work "over", "under", or
"a la" a *single* newtype, potentially changing its type arguments
but not changing it wholesale. Back in the day, Haskell couldn't
express that idea, but now it can (for the most part). We can take
advantage of that to improve inference and typed hole error messages.

Fixes love-haskell#15
sjakobi pushed a commit that referenced this issue Jul 29, 2019
The original concept of this API is to work "over", "under", or
"a la" a *single* newtype, potentially changing its type arguments
but not changing it wholesale. Back in the day, Haskell couldn't
express that idea, but now it can (for the most part). We can take
advantage of that to improve inference and typed hole error messages.

Fixes #15

Also remove support for older GHC:

`Coercible` seems to be really fragile under GHC versions before
8.4. 8.2 seems especially fussy: even when the package compiles,
use cases may fail mysteriously.
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

Successfully merging a pull request may close this issue.

1 participant