Code Monkey home page Code Monkey logo

lift-plugin's People

Contributors

mpickering avatar

Stargazers

Evan Relf avatar  avatar Daniel Kahlenberg avatar Sandy Maguire avatar

Watchers

James Cloos avatar  avatar  avatar  avatar

Forkers

j-mie6

lift-plugin's Issues

Combining pure and impure fragments

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)

Remove automatic application overloading

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.

Consider the BSD-3-Clause License

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?

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.