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

Runtime error by passing a function to an onClick #35

Open
tcoopman opened this issue Jun 18, 2017 · 5 comments
Open

Runtime error by passing a function to an onClick #35

tcoopman opened this issue Jun 18, 2017 · 5 comments

Comments

@tcoopman
Copy link
Contributor

I'm not sure if this is the best way to use TEA, but I've run into a runtime error in this situation:

type msg = Foo of (int * msg Tea.Cmd.t)

let msgs id = Tea.Cmd.call (fun callbacks -> ....)

let view =
  div [onClick (Foo (1, (msgs 1)))] []

I get an error on

let compareEventHandlerTypes left = function

because this uses ocaml.equal which doesn't like comparing functions:

var b_type = typeof b;
        if (a_type === "function" || b_type === "function") {
          throw [
                invalid_argument,
                "equal: functional value"
@OvermindDL1
Copy link
Owner

Doesn't Elm cause a runtime error as well in the same case? I know passing functions via messages is not 'safe' in the Elm style (nor storing them in the model).

I wonder if there is a way to turn this into a compile-time error, at the very least I will leave this open to research in to doing that (no method is popping immediately to mind)...

@stereobooster
Copy link

stereobooster commented Feb 21, 2018

One of the guarantees of Elm is that you will not see runtime errors in practice
-- https://guide.elm-lang.org/error_handling/

It uses immutability, effects and exhaustive check to do the trick.

@OvermindDL1
Copy link
Owner

It uses immutability, effects and exhaustive check to do the trick.

It fails at the 'will not see runtime errors in practice' quite a bit. There are a LOT of cases it will crash at runtime.

For note, OCaml actually does quite substantially more exhaustiveness checks than Elm with a far better type system (One good way to crash the runtime involves some number tricks that have occured in practice). Plus also immutability there.

And Elm's effects are... more like message passing processes, not effects.

@stereobooster
Copy link

There are a LOT of cases it will crash at runtime.

You are so right

Number 3 — function equality
-- https://medium.com/@eeue56/top-6-ways-to-make-your-elm-app-crash-at-runtime-562b2fa92d70

@OvermindDL1
Copy link
Owner

Heh, yeah I hit quite a number of them with fairly stock code when I was developing an Elm app (not even javascript related crashed, I know how to deal with the DOM), that combined with the hostile community steered me away from it, but it was still an interesting design that I wanted to pursue, however I had a lot of code that I'd have to rewrite, instead of doing that I made this bucklescript-tea library and did very minor edits to get it working with bucklescript instead and I'm using that now. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants