Skip to content

Instantly share code, notes, and snippets.

@kgashok
Last active April 30, 2016 23:47
Show Gist options
  • Save kgashok/4521f0e852d7e0984394280f35e0d1a2 to your computer and use it in GitHub Desktop.
Save kgashok/4521f0e852d7e0984394280f35e0d1a2 to your computer and use it in GitHub Desktop.
Modification of Rundberget's version at (https://gist.github.com/rundis/8b5a0fd09c3eb348dfc2aa7e862436b4) to use String as a stack
import SStack as Stack exposing (..)
import Html exposing (..)
reverseString : String -> String
reverseString str =
Stack.reverse str
main : Html.Html
main =
reverseString "Hello World !"
|> Html.text
module SStack where
import String
type alias SStack = String
empty : SStack
empty =
""
push : String -> SStack -> SStack
push tok stacks =
tok ++ stacks
pop : SStack -> Maybe (Char, SStack)
pop stacks =
String.uncons stacks
reverse : SStack -> SStack
reverse stack =
case (pop stack) of
Nothing ->
empty
Just(x, r) ->
push (reverse r) (String.fromChar x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment