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 with tuples #201

Closed
TheSeamau5 opened this Issue Mar 16, 2015 · 4 comments

Comments

Projects
None yet
4 participants
@TheSeamau5
Contributor

TheSeamau5 commented Mar 16, 2015

I am unable to pin down why this error happens but the failing code is surprisingly short:

smap : (a -> b -> (a,b)) -> a -> List b -> (a, List b)
smap f a list = case list of
  [] -> (a, [])
  b :: bs  ->
    let (a',b') = f a b
        (a'', list) = smap f a' bs
    in
        (a'', b' :: list)

test = smap (,) 0 [0]

which causes the following error:

Cannot read property '_0' of undefined


Open the developer console for more details.
@jvoigtlaender

This comment has been minimized.

Show comment
Hide comment
@jvoigtlaender

jvoigtlaender Aug 31, 2015

Contributor

I think this is a compiler error that has to do with name shadowing. Note that the runtime error goes away if you change the code to this:

smap : (a -> b -> (a,b)) -> a -> List b -> (a, List b)
smap f a list = case list of
  [] -> (a, [])
  b :: bs  ->
    let (a',b') = f a b
        (a'', list') = smap f a' bs
    in
        (a'', b' :: list)

or to this:

smap : (a -> b -> (a,b)) -> a -> List b -> (a, List b)
smap f a list = case list of
  [] -> (a, [])
  b :: bs  ->
    let (a',b') = f a b
        (a'', list') = smap f a' bs
    in
        (a'', b' :: list')

Can you close this issue here, check whether a corresponding issue is already open at the elm-compiler repo, and if not, open an issue there?

Contributor

jvoigtlaender commented Aug 31, 2015

I think this is a compiler error that has to do with name shadowing. Note that the runtime error goes away if you change the code to this:

smap : (a -> b -> (a,b)) -> a -> List b -> (a, List b)
smap f a list = case list of
  [] -> (a, [])
  b :: bs  ->
    let (a',b') = f a b
        (a'', list') = smap f a' bs
    in
        (a'', b' :: list)

or to this:

smap : (a -> b -> (a,b)) -> a -> List b -> (a, List b)
smap f a list = case list of
  [] -> (a, [])
  b :: bs  ->
    let (a',b') = f a b
        (a'', list') = smap f a' bs
    in
        (a'', b' :: list')

Can you close this issue here, check whether a corresponding issue is already open at the elm-compiler repo, and if not, open an issue there?

@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz Aug 31, 2015

Member

When you reopen, do you mind also putting in the generated JS? I think that'd help a lot in figuring out exactly what went wrong.

Member

evancz commented Aug 31, 2015

When you reopen, do you mind also putting in the generated JS? I think that'd help a lot in figuring out exactly what went wrong.

@rtfeldman

This comment has been minimized.

Show comment
Hide comment
@rtfeldman

rtfeldman Jan 2, 2016

Member

Cannot reproduce in 0.16.

I pasted this into try-elm:

import Html exposing (text)

main =
  text ("Hello, World!" ++ toString (test))

smap : (a -> b -> (a,b)) -> a -> List b -> (a, List b)
smap f a list = case list of
  [] -> (a, [])
  b :: bs  ->
    let (a',b') = f a b
        (a'', list) = smap f a' bs
    in
        (a'', b' :: list)

test = smap (,) 0 [0]

...and the screen displayed:

Hello, World!(0,[0])

@evancz I think this may have been fixed by the codegen updates in 0.16.

Member

rtfeldman commented Jan 2, 2016

Cannot reproduce in 0.16.

I pasted this into try-elm:

import Html exposing (text)

main =
  text ("Hello, World!" ++ toString (test))

smap : (a -> b -> (a,b)) -> a -> List b -> (a, List b)
smap f a list = case list of
  [] -> (a, [])
  b :: bs  ->
    let (a',b') = f a b
        (a'', list) = smap f a' bs
    in
        (a'', b' :: list)

test = smap (,) 0 [0]

...and the screen displayed:

Hello, World!(0,[0])

@evancz I think this may have been fixed by the codegen updates in 0.16.

@evancz evancz closed this Jan 2, 2016

@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz Jan 2, 2016

Member

Cool, thanks for following up on this!

Member

evancz commented Jan 2, 2016

Cool, thanks for following up on this!

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