Vorlesung 2
This commit is contained in:
parent
f4e8d17e50
commit
bcff353228
27
exampleCode/lecture2/state.hs
Normal file
27
exampleCode/lecture2/state.hs
Normal file
@ -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))
|
BIN
lecture2.pdf
Normal file
BIN
lecture2.pdf
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user