diff --git a/exampleCode/lecture2/state.hs b/exampleCode/lecture2/state.hs new file mode 100644 index 0000000..cda1e49 --- /dev/null +++ b/exampleCode/lecture2/state.hs @@ -0,0 +1,27 @@ +module Main where + +{- Hier eine Passende Definition der State-Monade einfügen... -} +{- z.B. Control.Monad.Trans.State aus dem transformers-package -} +{- oder Control.Monad.State aus dem veralteten mtl-package -} + +type CountState = (Bool, Int) + +startState :: CountState +startState = (False, 0) + +play :: String -> State CountState Int +play [] = do + (_, score) <- get + return score +play (x:xs) = do + (on, score) <- get + case x of + 'C' -> if on then put (on, score + 1) else put (on, score) + 'A' -> if on then put (on, score - 1) else put (on, score) + 'T' -> put (False, score) + 'G' -> put (True, score) + _ -> put (on, score) + play xs + +main = print $ runState (play "GACAACTCGAAT") startState +-- -> (-3,(False,-3)) diff --git a/lecture2.pdf b/lecture2.pdf new file mode 100644 index 0000000..cce3db1 Binary files /dev/null and b/lecture2.pdf differ