Created
April 30, 2016 08:15
-
-
Save prozacchiwawa/2fd34c7c73d8ec48c84167c034afca3e 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, Maybe Stack) | |
pop stack = | |
let | |
top = List.head stack | |
in | |
(top, List.tail stack) | |
stackIterator : Stack -> LazyList String | |
stackIterator stack = | |
let nextOf stack = | |
case pop stack of | |
(Just h, Just t) -> LL.cons h (nextOf t) | |
(Just h, Nothing) -> LL.cons h LL.empty | |
(Nothing, _) -> LL.empty | |
in | |
nextOf stack | |
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