" Free모나드 는 공짜라서 Free 모나드가 아닙니다. "
https://lionhairdino.github.io/posts/2024-12-15-freeMonadV2.html
하스켈 을 공부하고 있고, 모나드 를 알고 있는 분들 중, Free 모나드가 손에 잘 잡히지 않는 분들이 볼만한 상상 글입니다.(쉽게 쓰려고 수학을 뺀 게 아니라, 몰라서 수학적인 건 없습니다.)(SNS를 시작한지 얼마 안되어, 여기 저기 모두 올려 봅니다. 중복 정보를 받으시는 분들은 이해 부탁 드립니다.)

#Free모나드 #FreeMonad #모나드 #Monad #하스켈

Free 모나드

왜 이름이 프리 모나드이며, 프리 모나드는 어떤 이펙트를 합성하고 있는지 살펴 봤습니다.

Lionhairdino

To my surprise, the idea I had last night is actually working just fine in #RustLang.

So, my #VisualNovel #SpareTimeProject is now probably going to use an #eDSL encoded as a #FreeMonad which is wrapped in a #StateMonadTransformer.

Now I just need to continue working on it. I haven't made much progress in the last 9 months...

Nicolas Rinaudo THE DEBATABLY FREE MONAD Scalar Conference 2024
https://www.youtube.com/watch?v=Yci07bMTcsM

#fp #scala #freemonad #programming

Nicolas Rinaudo THE DEBATABLY FREE MONAD Scalar Conference 2024

YouTube

Yesterday I ported Haskell's State Monad Transformer to #RustLang. That should make tracking the game state in my #FreeMonad based embedded Domain Specific Language for scripting the story in my spare time #VisualNovel #GameDev project way easier.

Also, the currently released version of "higher" has the limitation that bindings in do-notation only work well with Copy types. The State Monad Transformer doesn't have this limitation and can store any state that is Clone.

@joenash The blog posts https://www.haskellforall.com/2012/07/purify-code-using-free-monads.html & https://www.haskellforall.com/2012/06/you-could-have-invented-free-monads.html by @GabriellaG439 about #FreeMonad|s seem related. They don't contain this claim verbatim, but a kinda lemma of it: «[…] we can always factor out impure parts from any code by using free monads. Free monads let you decompose any impure program into a pure representation of its behavior and a minimal impure interpreter[…]»

@donsbot

Purify code using free monads

Experienced Haskell programmers commonly advise newcomers to keep as much of their program as pure as possible. Purity confers many practic...

I've started some architecture work for my potential #VisualNovel spare time project. I must say I'm torn between using a #FreeMonad for storytelling, or going the usual #RustLang way of using a trait...

A Free Monad would decouple the storytelling from the user interaction completely, and its internal state would become trivial to manage.

A trait would allow to utilize Rust's borrow checker to ensure a situation's consistency. For instance one could tie a character's lifetime to the location.

On the topic of #FreeMonad in #RustLang: I found out that there is another package on crates.io, that was released a few weeks before my higher-free-macro macro:
https://crates.io/crates/algar

Unlike my code algar is using a generic type instead of a macro, what is possible because it has different Functor/Monad/... traits that use an associated type to specify the domain.

On the other hand, algar has limitations that higher-free-macro does not have. Its Monad can only bind with FnOnce, for instance.

crates.io: Rust Package Registry

I went ahead and published my small #FreeMonad crate for #RustLang officially today.

https://crates.io/crates/higher-free-macro

This crate employs a macro to create a Free Monad type for a user-supplied Functor. The Free Monad is implemented as a recursive data type with Box as indirection.

It uses the traits from the "higher" crate by @bodil to express what a Functor/Monad/etc. is.

crates.io: Rust Package Registry

Today I've added an example to my #FreeMonad in #RustLang project.
It is pretty bad code, but that's what happens if one intentionally makes bad decisions in order to highlight issues and potential workarounds...

For instance, I used a `Vec` where a 3-element array would have sufficed, making me write a ton more `clone()` calls than I ever wanted...

Still, I'm pretty happy how small the interpreter turned out, and how easy it was to focus on the actual game logic:
https://github.com/soulsource/higher-free-macro/tree/main/examples/text-adventure

higher-free-macro/examples/text-adventure at main · soulsource/higher-free-macro

A macro that allows to conjure a Free Monad for every Functor. This builds on the traits from the higher crate, and re-exports said crate. - higher-free-macro/examples/text-adventure at main · soul...

GitHub