Comments (7)
Care to expound?
from purescript-literals.
I'm writting on the paper only (I'm going to compile this later):
class Reflect t (s :: Symbol) where
reflect :: Proxy (Literal t s) -> t
instance reflectNumber :: (Number s) => Reflect Number s where
reflect _ = Literal.toValue (Literal.Number.numberLit :: Literal Number s)
So we can reflect any Literal
at hand and be able to represent default values on the type level just by using Literal n s
if I'm not wrong ;-)
from purescript-literals.
I'm not sure if such default values would be usable in practice though... Maybe I should experiment a bit before raising this discussion ;-)
I have doubts because even if we have mechanism to derive a type from defaults it won't be taken into account by the type checker. I mean even if we provide class UnLiteral l t | l -> t
and instance unLiteralNumber :: UnLiteral (Literal t s) t
we won't be able to type something based on this like:
type MyLiteral = Literal Number "80.0"
operateOnUnliteral :: UnLiteral MyLiteral r' => r' -> o
This doesn't bring the type of r'
Number
to the function body I think :-(
But maybe there is a context in which such generic reflection could be used.
from purescript-literals.
Possible usage (defaults... and maybe more):
from purescript-literals.
@jvliwanag Please take a look at examples - I was able to add an experimental function which based on reflection + typelevel evaluation produces record of fully polymorphic lenses for a given record. Here is an example usage.
P.S.
I should probably use a class from purescript-reflection - I'm going to migrate to type class from there when we agree if we want to introduce reflection instances here (I think it is worth it :-))
P.S.II. I have to revert back this change in Literal
kind - there should be a Symbol
there.
from purescript-literals.
@jvliwanag Do we want to include this reflection in the upcoming release? Should I prepare proper PR?
from purescript-literals.
I'll go try making a pre 1.0 release first. Need to familiarize myself first with the release process. Of course, a PR for your improvements are welcome and we can make another release then.
from purescript-literals.
Related Issues (5)
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-literals.