unisonweb / unison

A friendly programming language from the future
https://unison-lang.org
Other
5.75k stars 269 forks source link

something weird between typechecking and handlers #1386

Open aryairani opened 4 years ago

aryairani commented 4 years ago

Check out @pchiusano's gist for converting between algebraic effects and monads.

After you replace all cases of case/of with match/with, it typechecks, but doesn't produce any output. Even a watch expression like > 3 no longer produces output.

It's something to do with:

do : Monad f -> '{Monadic f} a -> f a
do m actions = handle !actions with
  pure = Monad.pure m
  bind = Monad.bind m
  go req = case req of
    {a} -> pure a
    {Monadic.eval fa -> k} -> bind fa (a -> handle k a with go)
  go

If you comment that function out of the file, then watch expressions start working again, even though do is guarded. It also breaks the file if I name it something other than do.

If I pull the let bindings for pure and bind above the handle/with, it works normally. Not sure if they were below for any particular reason (e.g. performance), or why there would be anything wrong with having them as they are.

Anyway, a working version of the gist is here.

Thanks to @byzantic for reporting.

aryairani commented 4 years ago

This .u file reproduces the issue, by producing no output — no errors or anything. It seems to be minimal, anything more I removed would wake up the typechecker.

foo m = handle yyy with
  pure = zzz m

> 3