guys.
I am currently trying to build a ZIO based application.
Question:
Is there any way to map and flatmap a composition of cats free monad and ZIO like the example below?
// Suppose we have a free monad like this
sealed trait SomeFMA[A]
type…
TL;DR: How do I write interpreters (run :: Lang a b -> whatever) for my Lang GADT?
I have a DSL:
data Lang a b where
F :: Lang x y
G :: Lang x y
I want to build programs like:
prog :: Lang a b
prog = G . F
And interpret them arbitrarily,…
I'm trying to get how free monads are working.
During this I get into the monad instance of Free, which is:
data Free f a = Pure a | Free (f (Free f a))
instance (Functor f) => Monad (Free f) where
return = Pure
Pure a >>= k = k a
Free m >>=…
I'm quite new to functional programming. However, I read about the Free Monad, and I'm trying to use it in a toy project. In this project, I model the stock's portfolio domain. As suggested in many books, I defined an algebra for the …
Suppose I have two algebras:
sealed trait OneAlgebra[A]
case class create() extends OneAlgebra[Unit]
case class update() extends OneAlgebra[Unit]
sealed trait TwoAlgebra[A]
case class add() extends TwoAlgebra[Unit]
case class delete() extends…
I've been doing an exercise to try to implement a basic Calculator with Free Monad.
As I understand the intention of the Free Monad and what I wanted to achieve is:
write my program (math expression) once run it with different interpreters.
Now i am…
I'm currently learning about free monads and I was toying with probably the simplest and most common example out there – Teletype:
{-# LANGUAGE DeriveFunctor #-}
import Control.Monad.Free
data TeletypeF a = Put String a
| Get…
I’m trying to derive MonadFree from a newtype and I just can’t work it out. My current code is:
newtype ApplicationStack s r p m =
ApplicationStack { runApplication :: StateT s (ReaderT r p) m }
deriving (Functor, Applicative, Monad, MonadState…
I'm experimenting with Free monad in Scalaz and trying to build simple interpreter to parse and evaluate expressions like:
dec(inc(dec(dec(10)))
where dec means decrement, inc means increment. Here is what I got:
trait Interpreter[A]
case class…
I'm playing around with Cats and Free Monads and I've written a toy REST Service algebra and a "program" called ensureOneProduct. Unfortunately ensureOneProduct has more boiler plate code than I'd like to see. Is there a better way to write the…
Suppose I have written an interpreter which has dependencies on other interpreters
def interpreter[S[_]](implicit kvs:KVS.ops[S, UUID, String]): Example ~> Free[S, ?]
Suppose my interpreter wants to surface events into a writer monad, so S has to…
I'm attempting to build a free monad (using free) which acts just like a StateT monad, but which allows you to also run monads over a base state AppState. I have a separate constructor LiftAction which holds those types. The idea is that you keep…
I have a free monad working that does what I want:
type FreeOperation[F] = Free[Operation, F]
sealed trait Operation[O]
case object IdentityOperation extends Operation[GraphTraversal[_, _]]
case class LabelOperation(label: String) extends…
Lets say I have the following free monad definition:
sealed trait SetOpsA[A]
case class AllSetNames() extends SetOpsA[Set[String]]
case class IdsFromSet(setName: String) extends SetOpsA[Set[String]]
object SetOps {
type SetOps[A] = Free[SetOpsA,…
I am trying to extend toy example explained in this blog post.
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE FlexibleContexts #-}
module FreeToy where
import Control.Monad.State
import Control.Monad.Free
import Data.Map (Map)
import qualified…