Created
February 24, 2009 17:57
-
-
Save brool/69686 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Monad.State | |
import System.Random | |
first lst = first' lst [] [] | |
first' [] _ result = reverse result | |
first' (h:t) found result = | |
if any (== h) found then first' t found (False:result) | |
else first' t (h:found) (True:result) | |
state_first' [] = return [] | |
state_first' (h:t) = do current <- get | |
let found = (any (== h) current) | |
put (if found then current else (h:current)) | |
rest <- state_first' t | |
return $ (not found):rest | |
-- isfound h = do current <- get | |
-- return (any (== h) current) | |
state_first lst = evalState (state_first' lst) [] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment