Skip to content

Instantly share code, notes, and snippets.

@prozacchiwawa
Created April 30, 2016 08:30
Show Gist options
  • Save prozacchiwawa/2ab6505111bd987980a08654a53d4b9b to your computer and use it in GitHub Desktop.
Save prozacchiwawa/2ab6505111bd987980a08654a53d4b9b to your computer and use it in GitHub Desktop.
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