FLP Labs
>= aplica si pastreaza tipul de apel
>> transforma
<=< compunere inversa
(Just 3) >>= (\ x -> if (x>0) then Just (x*x) else Nothing) => Just 9
(Just 3) >> (Just 6) => Just 6
f <=< g $ 3 => Just 10 (il ia pe 3, ii aplica g, si valorii obtinute ii aplica f)
type M = Identity
newtype Identity a = Identity { runIdentity :: a }
term0 = (App (Lam "x" (Var "x" :+: Var "x")) (Con 10 :+: Con 11)) => "42"
showM function for Identity monad
type M = Maybe
term0 = (App (Lam "x" (Var "x" :+: Var "x")) (Con 10 :+: Con 11)) => Just 42
without showM function (system defined for Maybe)
type M = Either String
term0 = (App (Lam "x" (Var "x" :+: Var "x")) (Con 10 :+: Con 11)) => Right 42
term1 = (App (Con 7) (Con 2)) [] => Left "should be function: 7"
Left “error text” or Left (show Wrong) for errors
-> intoarce lista raspunsurilor posibile
type M a = [a]
interp (App (Lam "x" (Var "x" :+: Var "x")) (Amb (Con 1) (Con 2)))) [] => [2,4]
New: Fail and Amb constructors
-> mediul de evaluare este vazut o stare care este citita atunci când avem nevoie de valorile variabilelor
-> dar starea nu va fi modificata(imutabila)
type M = EnvReader
newtype EnvReader a = Reader { runEnvReader
Environment -> a }
term0 = (App (Lam "x" (Var "x" :+: Var "x")) (Con 10 :+: Con 11)) => "42"
showM function
-> afisare de rezultate intermediare
type M = StringWriter
newtype StringWriter a = StringWriter { runStringWriter
(a, String) }
interp (Out (Con 41) :+: Out (Con 1)) [] => "Output: 41; 1; Value: 42"
instance Show-StrinWriter
-> numarul de pasi necesari pentru calcularea rezultatului (numar doar la adunare si aplicare de functie)
type M = InState
newtype IntState a = IntState { runIntState
Integer -> (a, Integer) }
interp ((Con 1 :+: Con 2) :+: Count) [] => "Value: 4; Count: 2"
modify(+1)
for modifying the counter
Cand le folosesc?
modify(+1) >> se foloseste fara DO
modify(+1) se foloseste in DO