Giter VIP home page Giter VIP logo

Comments (8)

nanotech avatar nanotech commented on July 23, 2024

Could Haskell's fromInteger/fromRational literal desugaring be used here? I think that could be done just in the parser and would avoid adding cases to unification.

from purescript-native.

andyarvanitis avatar andyarvanitis commented on July 23, 2024

Yeah, the end-goal would be to have functions like Haskell's fromInteger/fromRational, but I think there still needs to be a type representing the literals that is appropriately polymorphic. For GHC, you get:

Prelude> let x = 10
Prelude> :t x
x :: Num a => a
Prelude> let r = 10.0
Prelude> :t r
r :: Fractional a => a

I know the PureScript guys have been discussing and working on this for a while:
purescript/purescript#396
purescript/purescript#614
– maybe we can pick their brains.

I'm definitely open to implementation ideas/attempts, though; I might be missing something obvious.

from purescript-native.

nanotech avatar nanotech commented on July 23, 2024

Yeah, as I was imagining it, the types of the literals would be polymorphic with type class constraints, like GHC.

I gave implementation a try here, but ran into some limitations of the current C++ type class generation (dictionary parameters, I think?). Quite a few tests get past PureScript type checking now though, so I think that works at least. The ones that don't are hitting the monomorphism restriction and need type signatures.

Apparently PureScript's monomorphism restriction is actually a limitation of the implementation (thanks for those issue links) and not a feature as in Haskell, which might make using type classes here less appealing for now.

Maybe just using the .0 suffix and/or C-style 0i/0u suffixes to distinguish between numeric types at parse time would be simpler to start with.

from purescript-native.

andyarvanitis avatar andyarvanitis commented on July 23, 2024

I just had a look at your test implementation, and I think it would still be an improvement over what I currently have. It just needs a couple fixes in CodeGen/Cpp.hs to get it working. I would also get the inliner to recognize fromInteger and avoid them in the generated C++ code, where safe.

I suppose we could also just make integral literals Integer for now (and floating literals Number), and allow implicit conversions to Number, since really, it's not particularly unsafe in the C++ world. We could then revisit it all as PureScript tackles the relevant issues. Not sure I'd want to do that, though.

from purescript-native.

andyarvanitis avatar andyarvanitis commented on July 23, 2024

I've just checked in a few changes related to integer handling: 7923698

The "internal" Integral type is gone. fromInteger is now defined and available in the Prelude, but it is not automatically inserted by the parser (although I was experimenting with it and have some support for it in place).

So for now, the rules are:

  • Integer literals can be used for all integral types, meaning Integer, Int, and Char
  • If inferred, an integral literal is of type Integer
  • Literals with a decimal point must be used for Number (and aliases Double and Float) types
  • A number of the PureScript tests won't pass, and will need to be changed (in this fork) to accommodate these rules, but I think that's reasonable given the introduction of actual integer types.

from purescript-native.

nanotech avatar nanotech commented on July 23, 2024

Looks good! Nice to see all those tests passing already too.

from purescript-native.

andyarvanitis avatar andyarvanitis commented on July 23, 2024

PureScript has now added built-in Int support, so the next version of Pure11 (after refactoring) will leverage that work.

from purescript-native.

andyarvanitis avatar andyarvanitis commented on July 23, 2024

Completely switched over to PureScript's Int way of doing things now, so closing this ticket.

from purescript-native.

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.