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

Need support of error to represent unrecoverable logical error #108

Open
zonyitoo opened this issue Mar 11, 2015 · 2 comments
Open

Need support of error to represent unrecoverable logical error #108

zonyitoo opened this issue Mar 11, 2015 · 2 comments

Comments

@zonyitoo
Copy link

We probably need support of error just like the one in Haskell. It won't be able to write one by user, because that will cause a type mismatch error.

Example use case:

let car [A] (l : PolyList[A]) : A =
    case l of
        Nil         -> error "Call `car` on a empty list"
     |  Cons x xs   -> x;

If I define error like this

let error (msg : String) = {
    java.lang.System.err.println(msg);
    java.lang.System.exit(1);
    ()
};

It won't compile, because of type mismatch. So I think compiler should see error function as a special case, or provide mechanisms to support throwing exception.

In Haskell, the message that sent from error function could be caught by Control.Exception.catch.

The definition of error in Haskell is

error :: [Char] -> a
@zonyitoo
Copy link
Author

Moreover, if I define error like this

let error [A] (msg : String) : A = {
    java.lang.System.err.println(msg);
    java.lang.System.exit(1);

    -- What should I write here??
};

@brunocdsoliveira
Copy link

Perhaps we need an easy way to add primitives into the compiler, including error and tracing features. Maybe @bixuanzju can think a bit about this.

@xnning xnning mentioned this issue Apr 29, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants