mpickering / lift-plugin Goto Github PK
View Code? Open in Web Editor NEWA plugin which does something very magical with Template Haskell's Lift type class
A plugin which does something very magical with Template Haskell's Lift type class
If we consider the staged power function, we observe a fundamental difficulty of writing programs polymorphic in their stage.
staticPower_s :: Syntax r => Int -> r Int -> r Int
staticPower_s n k = if n == 0
then pure 1
else ([ k * (staticPower_s (n - 1) k) ])
Notice that the conditional and scrutinee are both statically evaluated using the non-overloaded versions of if
and ap
.
However, we could also use the overloaded variants and then instantiate them to Identity
. The hope being that this would provide a more uniform treatment.
staticPower_s :: Syntax r => Int -> r Int -> r Int
staticPower_s n k = runIdentity $ _if (pure (==) <*> pure n <*> pure 0)
(pure (pure 1)
(pure ([ k * (staticPower_s (n - 1) k) ]))
The type of the _if :: Identity Bool -> Identity (r Int) -> Identity (r Int) -> Identity (r Int)
At the moment any application is desugared to the _ap
combinator. This seems like a good idea
but in practice it doesn't work very well as you end up writing pure (+) n (pure 1)
.
The "obvious" solution which is very hairy is to also automatically lift variables by wrapping them with pure
.
The results of this can be seen on the https://github.com/mpickering/lift-plugin/tree/wrap branch. The problem here is that when you observe a variable x
, how do we decide whether we want to lift it or not? If x :: r a
then it is already lifted but what about x :: IO a
, is that lifted? The implementation got very out of hand anyway with a very ad-hoc type checker plugin.
So, the solution here is to overload neither ap
or pure
and use idiom brackets when we want to overload either. The idiom bracket overloading is provided by Oleg's plugin which we just run at the start.
This is the only way which we overload ap
and pure
now at the expense of a slightly more verbose program.
Hi Matt!
I've just last night released Parsley onto hackage, and I was hoping to release my updated fork of the lift-plugin (along with the idioms-plugin, if Oleg is happy) together into a Parsley-specific bundle. Firstly, would you be ok with that (obviously fully acknowledged), and, if so, can you put the BSD-3-Clause License onto this repo so it's legal for me to do it?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.