Giter Site home page Giter Site logo

Comments (6)

fizruk avatar fizruk commented on August 23, 2024

I would appreciate if someone proved the implementation wrong/correct or at least pointed to the laws to be considered.

from free.

ekmett avatar ekmett commented on August 23, 2024

I'm going to leave this one open until I can get a longer look at it.

from free.

fizruk avatar fizruk commented on August 23, 2024

Here is a bunch of "laws":

listen (return a) = return (a, mempty)
listen (tell w) = tell w >> return ((), w)
listen (m >>= k)
  = listen m >>= \(x, w) -> listen (k x) >>= \(y, w') -> return (y, (w <> w'))

pass (return (a, f)) = tell (f mempty) >> return a
pass (tell w >> m) = pass (second (. (w <>)) `liftM` m)
pass (m >>= k)
  = pass ((,const mempty) `liftM` listen m) >>= \(x, w) -> pass (tell w >> k x)

I believe these capture the expectations given that pass is the only way to modify output.

This modification gets rid of Functor constaint and resolves issue (extra delay) with the second law (listen-tell):

instance (MonadWriter w m) => MonadWriter w (IterT m) where
  tell = lift . tell
  listen (IterT m) = IterT $ liftM concat' $ listen (fmap listen `liftM` m)
    where
      concat' (Left  x, w) = Left (x, w)
      concat' (Right y, w) = Right $ second (w <>) <$> y
  pass m = IterT . pass' . runIterT . hoistIterT clean $ listen m
    where
      clean = pass . liftM (\x -> (x, const mempty))
      pass' = join . liftM (either
                             (\((x, f), w) -> tell (f w) >> return (Left x))
                             (return . Right . IterT . pass' . runIterT))

I don't know if this fulfills all of the outlined laws.

from free.

ekmett avatar ekmett commented on August 23, 2024

Going through closing out old issues. I have no issue with this instance if you want to add it.

from free.

fizruk avatar fizruk commented on August 23, 2024

Sure, will prepare a pull request now.

from free.

fizruk avatar fizruk commented on August 23, 2024

Merged in #45.

from free.

Related Issues (20)

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.