Comments (8)
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.
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.
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.
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.
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
, andChar
- If inferred, an integral literal is of type
Integer
- Literals with a decimal point must be used for
Number
(and aliasesDouble
andFloat
) 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.
Looks good! Nice to see all those tests passing already too.
from purescript-native.
PureScript has now added built-in Int
support, so the next version of Pure11 (after refactoring) will leverage that work.
from purescript-native.
Completely switched over to PureScript's Int
way of doing things now, so closing this ticket.
from purescript-native.
Related Issues (20)
- ObjectUpdate seems to need deep copy HOT 2
- Cannot find ls/ls.h and rs/rs.h HOT 2
- Incorrect equality check in Data_Interval_Duration_Iso HOT 3
- Returning a constant from the ffi HOT 7
- "attribute 'haskell-nix' missing" when building with nix HOT 3
- error building purescript-dotlang HOT 16
- Support spago alternate entry point option
- ffi array type interop with opaque types HOT 7
- zero-fill shift right operator doesn't exist HOT 11
- pass arguments to run HOT 2
- stack nix integration HOT 1
- Problems with nix toolchain HOT 9
- Consider combining executables (and specify backend with switch) HOT 5
- un-gitignore cabal files HOT 2
- cpp binary size HOT 4
- Update to PureScript 0.14 HOT 5
- Webassembly / Emscripten with C++ HOT 1
- Upgrade to Latest PureScript Version
- Backend "psgo" exited with error:1 HOT 2
- go module initialization HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from purescript-native.