Git Product home page Git Product logo

Comments (2)

andrewthad avatar andrewthad commented on September 26, 2024

From what I learned in #14, I thought that it would be possible to also write the functions

mapProgramT :: (forall a. instr1 a -> instr2 a) -> ProgramT instr1 m b -> ProgramT instr2 m b
hoistProgramT :: (forall b. m b -> n b) -> ProgramT instr m a -> ProgramT instr n b

without pattern matching on ProgramT. However, I still cannot find a way to write mapProgramT with pattern matching, so I think that this PR is still relevant.

from operational.

HeinrichApfelmus avatar HeinrichApfelmus commented on September 26, 2024

The same ideas from #14 can be used to write mapProgramT. Here is one way to do it:

mapProgramT :: Monad m => (forall a. instr1 a -> instr2 a)
    -> ProgramT instr1 m b -> ProgramT instr2 m b
mapProgramT f p = do
    v <- lift $ viewT p
    case v of
        Return a -> return a
        i :>>= k -> singleton (f i) >>= mapProgramT f . k

If I were to export the constructors, then this would kind of the defeat the purpose of the library. (Though I'm willing to compromise for the sake of efficiency). Relying on viewT only makes sure that the monad laws and the lifting laws are always satisfied. In contrast, having access to the internal constructors risks breaking these laws.

from operational.

Related Issues (17)

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.