Created
April 30, 2016 08:30
-
-
Save prozacchiwawa/2ab6505111bd987980a08654a53d4b9b 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 Html exposing (..) | |
import String | |
import Lazy.List as LL exposing (LazyList) | |
type alias Stack = List String | |
push : String -> Stack -> Stack | |
push tok stack = | |
(tok :: stack) | |
pop : Stack -> (Maybe String, Stack) | |
pop stack = | |
case stack of | |
hd :: tl -> (Just hd, tl) | |
_ -> (Nothing, []) | |
stackIterator : Stack -> LazyList String | |
stackIterator stack = | |
LL.iterate (\(mhd, tl) -> pop tl) (pop stack) | |
|> LL.map fst | |
|> LL.takeWhile (\a -> a /= Nothing) | |
|> LL.map (Maybe.withDefault "") -- Default just for theoretical completeness | |
reverseString: String -> String | |
reverseString incoming = | |
let | |
stringStack = incoming | |
|> String.split "" | |
|> List.foldl push [] | |
in | |
-- How to use pop() here? | |
LL.foldr String.append "" (stackIterator stringStack) | |
main : Html | |
main = | |
"Hello World!" | |
|> reverseString | |
|> toString | |
|> text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment