Questions tagged [free-monad]

Free monads give a general way of turning functors into monads. They are useful for many tree-like structures and domain specific languages.

Free monads give a general way of turning functors into monads. They are useful for many tree-like structures and domain specific languages.


Free monads on hackage: free

Some useful StackOverflow questions:

Posts about free monads in Haskell:

Posts about free monads in Scala:

161 questions
1
vote
0 answers

How to map and flatmap a composition of cats free monad and ZIO

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…
Jun
  • 23
  • 1
  • 5
1
vote
1 answer

How can I polymorphically interpret an Arrow-like GADT DSL?

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,…
Josh.F
  • 3,666
  • 2
  • 27
  • 37
1
vote
2 answers

Understanding the use of bind in free monad

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 >>=…
kozer
  • 140
  • 1
  • 2
  • 8
1
vote
1 answer

Using the Free Monad in Functional Domain Design

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 …
riccardo.cardin
  • 7,971
  • 5
  • 57
  • 106
1
vote
1 answer

How to add two Algebras in one interpreter in scala using natural transformation

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…
1
vote
1 answer

Interpreters for the Free Monad

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…
AdrianS
  • 1,980
  • 7
  • 33
  • 51
1
vote
1 answer

Interpreting the Teletype free monad in the RWS monad

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…
Dan Oneață
  • 968
  • 7
  • 14
1
vote
1 answer

Deriving MonadFree from a newtype with a transformer stack

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…
tomphp
  • 307
  • 1
  • 4
  • 10
1
vote
1 answer

Understanding Free monad in scalaz

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…
St.Antario
  • 26,175
  • 41
  • 130
  • 318
1
vote
1 answer

Handling conditions and Free Monads in Scala

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…
Tim Stewart
  • 5,350
  • 2
  • 30
  • 45
1
vote
0 answers

Using Monad Ops in a Free Monad interpreter

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…
J Pullar
  • 1,915
  • 2
  • 18
  • 30
1
vote
1 answer

Zoom instance over Free Monad

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…
Chris Penner
  • 1,881
  • 11
  • 15
1
vote
1 answer

Scala: How do I compose a list of operations into a free monad?

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…
prismofeverything
  • 8,799
  • 8
  • 38
  • 53
1
vote
0 answers

Scala Cats: Iterate over a result from a free monad and execute a free monad operation for each of those results

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,…
R Pieters
  • 107
  • 1
  • 6
1
vote
0 answers

Free monad extending toy example

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…
venu gangireddy
  • 107
  • 1
  • 8
1 2 3
10
11