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

How to assign a value from the IO monad to a RankNType qualified constructor

(UPDATED) I have made an interface using a Free Monad to a generic data store. I want to place the specific interpreter (:: DataStore a -> IO a) chosen by the user at run time into a state monad along with some other information. I cannot seem to…
John F. Miller
  • 26,961
  • 10
  • 71
  • 121
1
vote
1 answer

How do I leverage the MonadReader instance of Free?

I want to use Reader in my DSL that I created using a Free monad. I notice that there is a instance of MonadReader for Free here: https://hackage.haskell.org/package/free-4.12.1/docs/src/Control-Monad-Free.html#line-264 If I try to call ask inside…
Joe Hillenbrand
  • 845
  • 9
  • 26
1
vote
1 answer

Is it possible to extend free monad parsers?

This is a follow up to Is it possible to extend free monad interpreters? or better the reverse. I recently revisited the project that the previous question stemmed from. This time I try to parse the file into the data structure. Problem is that I…
fho
  • 6,787
  • 26
  • 71
0
votes
1 answer

Transforming Doobie ConnectionIO[Option[Int]] without explicit match

I have a ConnectionIO[Option[Int]] and map over the Option to produce a ConnectionIO[Option[String]] with a query the Some[Int] otherwise keep the Nones. I was able to do this with aforcomprehension and amatch`: def findWidgetByOwner(name: String):…
Arne Claassen
  • 14,088
  • 5
  • 67
  • 106
0
votes
1 answer

Scala free monad combining with Doobie

I've been spending time lately to grasp FP concepts and especially the free monad. I think I understand the idea behind free monads quite well, but a question arose. I've been using Doobie for a bit which is built on top of free monads. For me, it…
Mauro Palsgraaf
  • 237
  • 3
  • 13
0
votes
1 answer

How to write a DSL based on free monad?

I'm playing with free monads in Haskell and I got stuck with defining the functions that lift the functor constructors in the Free monad. I have the AppF functor as a sum of several functors, each representing an effect. One of these functors is…
vidi
  • 2,056
  • 16
  • 34
0
votes
1 answer

How do I chain action and interpret them together with Scalaz?

I am trying to learn how to use FreeMonads to implement interpreters for my services. Suppose I have sealed trait ServiceAction[T] extends Product with Serializable case class ConsumeCommand(cmd: AccruePoints) extends…
sowen
  • 1,090
  • 9
  • 28
0
votes
1 answer

Why can't the compiler deduce the Functor type in the Free Applicative examples?

module Main where data Toy b next = Output b next | Bell next | Done data FixE f e = Fix (f (FixE f e)) | Throw e -- The working monadic function catch :: (Functor f) => FixE f e1 -> (e1 -> FixE f e2) -> FixE f e2 catch (Fix x) f = Fix…
Marko Grdinić
  • 3,798
  • 3
  • 18
  • 21
0
votes
2 answers

Free Monad to generate blog feed in Scala

Suppose I need to add generate an RSS/Atom feed for a blog site. I am thinking about the "Feed Monad Interpreter" pattern. That is, I would define a DSL with primitives Blog and BlogPost, a Free monad, which is just a tree of these primitives, and…
Michael
  • 41,026
  • 70
  • 193
  • 341
0
votes
1 answer

What does Pure mean in Free monad in Haskell?

I try to learn free monads. I found following: data Free f r = Free (f (Free f r)) | Pure r What does Pure mean? And why do I need r with Pure?
RuF
  • 548
  • 1
  • 11
  • 31
-1
votes
1 answer

Building a compiler for Free monad (Cats library)

I'm trying to get my head around monads and Cats. Following some examples (e.g.cats) I wrote the code like below. But can't figure out how to make compiler to do what I need and to compile, actually. import cats.Id import cats.free.Free import…
kikulikov
  • 2,512
  • 4
  • 29
  • 45
1 2 3
10
11