Book Author, Experienced Software Architect, Functional Programming Expert, Educator and International Speaker
Contact Information
- Location: Dubai, UAE
- Phone: +971586924747
| -- Option 1: State as an eDSL | |
| data StateMethod s next | |
| = Put s (() -> next) | |
| | Get (s -> next) | |
| instance Functor (StateMethod s) where | |
| fmap f (Put st next) = Put st (f . next) | |
| fmap f (Get next) = Get (f . next) |
| module StateLangSpec where | |
| import Test.Hspec | |
| import Data.IORef | |
| import Control.Monad.Free.Church | |
| data StateMethod s next | |
| = Put s (() -> next) | |
| | Get (s -> next) |
| (* Free monads in OCaml | |
| Code for my talk: | |
| https://www.youtube.com/live/KdMuSH9pGsw?si=wybc5UCBua-uIzBU | |
| *) | |
| (* Free monads are implemented with the help of these resourses: *) | |
| (*http://rgrinberg.com/posts/free-monads-in-the-wild-ocaml/*) |
| {-# LANGUAGE DataKinds #-} | |
| {-# LANGUAGE FlexibleInstances #-} | |
| {-# LANGUAGE FlexibleContexts #-} | |
| {-# LANGUAGE TypeApplications #-} | |
| {-# LANGUAGE TypeOperators #-} | |
| {-# LANGUAGE TypeFamilies #-} | |
| {-# LANGUAGE FunctionalDependencies #-} | |
| module Main where |