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

Default onError instance in REPL #130

Open
ppolesiuk opened this issue Jun 16, 2024 · 0 comments
Open

Default onError instance in REPL #130

ppolesiuk opened this issue Jun 16, 2024 · 0 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@ppolesiuk
Copy link
Member

ppolesiuk commented Jun 16, 2024

It would be nice to have the default instance of ~re/~onError in REPL. However the following naive definition:

data Error (effect E) = { raise : {type T} -> Unit ->[E] T }
handle {effect=RE} err = Error { raise = effect () / _ => () }
let ~onError = err.raise

have a huge drawback: when we type [].hdErr, the REPL would exit immediately. The problem can be solved at library level, by adding the following file (ReplUtils.fram) to the standard library:

pub data ReplUtils (effect E) =
  { raise  : {type T} -> Unit ->[E] T
  , commit : Unit ->[E] Unit
  }

pub handle {effect=ReplRE} repl = ReplUtils
  { raise  = effect () / _ => fn snapshot =>
    printStrLn "Runtime Error!";
    match snapshot with
    | None   => ()
    | Some f => f ()
    end
  , commit = effect () / r => fn _ =>
    let rec snapshot () = r () (Some snapshot) in
    snapshot ()
  }
  return  x => fn _ => x
  finally c => c None

let _ = repl.commit ()

pub let ~onError = repl.raise

but this would not solve all the problems:

> import List ;;
> import open ReplUtils ;;
> let foo x = x ;;
> [].hdErr ;;
: a
Runtime Error!
> foo 42 ;;
<stdin>:1:1-3: fatal error: Unbound variable foo
>

To do it correctly, we have to call repl.commit method after each REPL command, but this requires changes in the type-checker (or desugaring)

@ppolesiuk ppolesiuk added the enhancement New feature or request label Jun 16, 2024
@forell forell added the good first issue Good for newcomers label Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants