Skip to content

Error handling #53

Description

@jdpage

We should probably think about our story for this at some point.

We could add generics/templates and discriminated unions and go for a Result type, but that's... a lot.

We could do multiple return. Maybe say that you return your error first, then your value, and provide a syntax...

fun foo(a: u8) -> err, u8
  -- do something
endfun

fun bar() -> err, u8
  let x = try foo(7)    -- causes early-return on error
  return x + 7          -- returns ok as the error
endfun

-- bar desugars to this, where e is some kind of gensym
fun bar() -> err, u8
  let e, x = foo(7)
  if e != ok do  return e  end
  return ok, x + 7
end

EDIT: Of course, err is a new type... it's one byte wide, has the special value literal ok, and allows 1-255 as literals. You can't do arithmetic with it or assign u8s to it. If a conditional expression has type err, ok is considered truthy.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions