haskell - Rewrite rule / specialisation type error with universally quantified constraints -


i trying implement type-specific specialisations of functions work prisms, , having difficulty ghc 8. (i encounter different problem ghc < 8, that's question).

a (contrived) minimal example of problem:

foo :: prism' s -> prism' s foo = id  {-# rules "foo/foo'" foo = foo' #-} foo' :: prism' char bool -> prism' char bool foo' = id 

this causes compiler error:

error: • couldn't match type ‘p0 bool (f0 bool) -> p0 char (f0 char)’                  ‘forall (p :: * -> * -> *) (f :: * -> *).                        (choice p, applicative f) =>                        p bool (f bool) -> p char (f char)’   expected type: prism' char bool     actual type: p0 bool (f0 bool) -> p0 char (f0 char) • in expression: foo'   when checking transformation rule "foo/foo'" 

it looks me 1 side of rewrite rule type checking "forgets" context. going on here, , how can make ghc happy?

this in essence old problem rank-n types don't make proper hierarchy of type more , less general. seems specific case could resolvable, it's not possible write rewrite rules general rank-n functions.

fortunately, not of issue lenses , friends, because these have monomorphic version available!

foo₀ :: aprism' s -> aprism' s foo₀ = id  {-# rules "foo/foo'" foo₀ = foo' #-} foo' :: aprism' char bool -> aprism' char bool foo' = id  foo :: prism' s -> prism' s foo p = cloneprism $ foo₀ (cloneprism p) 

Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -