Hi, could someone explain how to use raiseUnder2/3. I'm trying to turn this into a reinterpreting version.
-- | Cut a `Methodology` into two pieces at a midpoint.
cutMethodology :: forall b c d r a.
Members '[ Methodology b c
, Methodology c d] r
=> Sem (Methodology b d ': r) a
-> Sem r a
cutMethodology = interpret \case
Process b -> process @b @c b >>= process @c @d
So I do
cutMethodology' :: forall b c d r a.
Sem (Methodology b d ': r) a
-> Sem (Methodology b c ': Methodology c d ': r) a
cutMethodology' = raiseUnder2 >>> cutMethodology @b @c @d
But then I get
error:
• Couldn't match ‘c’ with ‘b’
arising from a use of ‘cutMethodology’
‘c’ is a rigid type variable bound by
cutMethodology' :: forall b c d (r :: [(* -> *) -> * -> *]) a.
Sem (Methodology b d : r) a
-> Sem (Methodology b c : Methodology c d : r) a
at /home/lc/Source/gitlab.com/homotopic-tech/flashblast/src/FlashBlast/Domain.hs:(51,1)-(53,72)
‘b’ is a rigid type variable bound by
cutMethodology' :: forall b c d (r :: [(* -> *) -> * -> *]) a.
Sem (Methodology b d : r) a
-> Sem (Methodology b c : Methodology c d : r) a
at /home/lc/Source/gitlab.com/homotopic-tech/flashblast/src/FlashBlast/Domain.hs:(51,1)-(53,72)
• Known types:
cutMethodology' :: Sem (Methodology b d : r) a
-> Sem (Methodology b c : Methodology c d : r) a
-- /home/lc/Source/gitlab.com/homotopic-tech/flashblast/src/FlashBlast/Domain.hs:54:1
|
54 | cutMethodology' = raiseUnder2 >>> cutMethodology @b @c @d
cutMethodology' :: forall r a.
Sem (Methodology Text Int ': r) a
-> Sem (Methodology Text String ': Methodology String Int ': r) a
cutMethodology' = raiseUnder2 >>> cutMethodology
Mmm no combination of those work. Same error like this:
cutMethodology' :: forall b c d r a.
Sem (Methodology b d ': r) a
-> Sem (Methodology b c ': Methodology c d ': r) a
cutMethodology' f = f & raiseUnder2 @(Methodology b c) @(Methodology c d)
& cutMethodology @b @c @d
cutMethodology' :: forall b c d r a.
Sem (Methodology b d ': r) a
-> Sem (Methodology b c ': Methodology c d ': r) a
cutMethodology' f =
let
sem' :: Sem (Methodology b d : Methodology b c : Methodology c d : r) a
sem' = raiseUnder2 f
in sem' & cutMethodology @b @c @d
cutMethodology' :: forall b c d r a.
Sem (Methodology b d ': r) a
-> Sem (Methodology b c ': Methodology c d ': r) a
cutMethodology' f =
let
sem' :: Sem (Methodology b d : Methodology b c : Methodology c d : r) a
sem' = raiseUnder2 f
in sem' & cutMethodology @b @c @d @(Methodology b c ': Methodology c d ': r)
cutMethodology'' :: forall b c d r a.
Sem (Methodology b d ': r) a
-> Sem (Methodology b c ': Methodology c d ': r) a
cutMethodology'' = reinterpret2 \case
Process b -> process @b @c b >>= process @c @d t
I get
Ambiguous use of effect 'Methodology'
---
Maybe-fix:
add (Member (Methodology c d) (Methodology b c
: Methodology c d : r)) to the context of
the type signature
If you already have the constraint you want, instead
add a type application to specify
'c', and 'd' directly, or activate polysemy-plugin which
can usually infer the type correctly.
|
64 | Process b -> process @b @c b >>= process @c @d
looks like the type class resolution method somehow decides that "yes, this is it, Methodology b _must match Methodology b _", only later "realises" that the second class argument differ, resulting in an error
Hi, could someone explain how to use raiseUnder2/3. I'm trying to turn this into a reinterpreting version.
So I do
But then I get
Shouldn't this work?
honestly kind of hard to debug for me without explicit code
did you try adding explicit types to everything?
also, try doing the eta expanded version, although it's probably not an issue here
It compiles successfully with concrete types.
I'd guess it's enough to add type applications to
raiseUnder2
or maybe just use
(.)
instead of(>>>)
Mmm no combination of those work. Same error like this:
if you do
?
Like
Also same
if you type-apply the
r
tocutMethodology
?Same
does it work with
reinterpret2
?How do I call?
same as
cutMethodology
, but with the signature ofcutMethodology'
this alone doesn't work either
ah, hmm
maybe it's the type family. if
reinterpret2
doesn't work (or also if it does), try using twoMember
constraints.highly doubt, the type family has enough information to fully evaluate
Two member constraints doesn't change
you win, Georgi!
reinterpret2 is this right?
I get
where's this "Maybe-fix" even coming from
Maybe clippy plugin
ah
what?
https://github.com/ArturGajowy/ghc-clippy-plugin, ah this thing I guess, cool
Yeah that
strangely, this works:
here there's no two
Methodology
s that have the same first type argumentsmaller repro:
this compiles
lol
notably, it doesn't, if I remove the
Nat
s, with an ungodly kind errorI think it's compiling without the Nats for me
further reduced
starting to look like a ghc bug/deficiency tbh
looks like the type class resolution method somehow decides that "yes, this is it,
Methodology b _
must matchMethodology b _
", only later "realises" that the second class argument differ, resulting in an errorI'll try to further slim it down later
does it work if you remove one type param of
Methodology
?I don't know how to emulate the same situation with only one type param
Did you say that last one works for you or doesn't?
last one I posted compiles
unless I forgot to save or something
Yup me too