Git Product home page Git Product logo

Comments (8)

evancz avatar evancz commented on May 18, 2024

Thanks for the report! The server is back up, and I'll work on figuring this one out. The type you describe is recursive, not infinite (I think this is a standard distinction, not sure though). The point is that the type of DragCircle can be written down with a finite amount of characters. This sort of thing should type-check, but I'll look into this more.

The mutually recursive functions you define (move and rest) actually have an infinite type:

move :: (Int,Int) -> Bool -> ( (Int,Int) -> Bool -> ( (Int,Int) -> Bool -> (...) ) )

I should be detecting this and throwing an error, but I guess not in this case!

Were you also seeing this behavior on functions that did not have infinite types?

from compiler.

joeyadams avatar joeyadams commented on May 18, 2024

Were you also seeing this behavior on functions that did not have infinite types?

I don't think so. I'm pretty sure dragCircle had an infinite type. Going by my definition above:

dragCircle :: (Form, (Number, Number) -> Bool -> (Form, (Number, Number) -> Bool -> (Form, (Number, Number) -> Bool -> ...)))

I used type in the Haskell sense, meaning a type alias. Does Elm treat type differently?

Also, note that if you change the offending code sample to:

move pos down = rest
rest pos down = (move, rest)

It doesn't crash, it just accepts the code (which Haskell rejects due to an occurs check failure).

from compiler.

joeyadams avatar joeyadams commented on May 18, 2024

To clarify, I didn't use the type keyword in the actual code. The type signatures I gave were the types I was expecting the code to have.

from compiler.

evancz avatar evancz commented on May 18, 2024

Ok, makes sense. I was treating type as data in my mind. I'll work on this!

from compiler.

joeyadams avatar joeyadams commented on May 18, 2024

I found a more innocent-looking piece of code that blows up the compiler:

f = foldr1 (:) [1..10]

The problem is that the Elm compiler does not seem to implement an occurs check. Namely, when unifying types, and you have a situation like this:

unify a [[a]]

This should be treated as a type error, since the substitution a ==> [[a]] forms an infinite type.

In general, when unifying a type variable a with type T:

  • If T is the type variable a, no need for a substitution.
  • If T contains the type variable a (e.g. [a], Maybe a, a -> Int), produce an "occurs check" error.

Typing Haskell in Haskell, section 6 describes unification and matching algorithms pretty nicely.

from compiler.

evancz avatar evancz commented on May 18, 2024

I am pretty certain you are correct, and I believe this can be corrected pretty easily. I'll take a look now.

I'll take a read through the link you provided to see if I can clean things up / find other mistakes!

from compiler.

evancz avatar evancz commented on May 18, 2024

Ok, fixed and pushed to master!

from compiler.

evancz avatar evancz commented on May 18, 2024

Released!

from compiler.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.