Last active
April 30, 2016 23:47
-
-
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
This file contains 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 SStack as Stack exposing (..) | |
import Html exposing (..) | |
reverseString : String -> String | |
reverseString str = | |
Stack.reverse str | |
main : Html.Html | |
main = | |
reverseString "Hello World !" | |
|> Html.text |
This file contains 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
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