Browse Source

Figure 2.2. Implementation of stacks using the build-in type of lists.

master
Aaron VonderHaar 5 years ago
commit
30c8f3deca
  1. 2
      .gitignore
  2. 35
      figures/2.2 Implementation of stacks/Stack.elm
  3. 14
      figures/2.2 Implementation of stacks/elm-package.json

2
.gitignore

@ -0,0 +1,2 @@
elm-stuff/
index.html

35
figures/2.2 Implementation of stacks/Stack.elm

@ -0,0 +1,35 @@
module Stack exposing (..)
type Stack a
= Stack (List a)
empty : Stack a
empty =
Stack []
isEmpty : Stack a -> Bool
isEmpty (Stack s) =
List.isEmpty s
cons : ( a, Stack a ) -> Stack a
cons ( x, Stack s ) =
Stack (x :: s)
head : Stack a -> Maybe a
head (Stack s) =
List.head s
tail : Stack a -> Maybe (Stack a)
tail (Stack s) =
case s of
[] ->
Nothing
_ :: rest ->
Just (Stack rest)

14
figures/2.2 Implementation of stacks/elm-package.json

@ -0,0 +1,14 @@
{
"version": "1.0.0",
"summary": "helpful summary of your project, less than 80 characters",
"repository": "https://github.com/user/project.git",
"license": "BSD3",
"source-directories": [
"."
],
"exposed-modules": [],
"dependencies": {
"elm-lang/core": "4.0.1 <= v < 5.0.0"
},
"elm-version": "0.17.0 <= v < 0.18.0"
}
Loading…
Cancel
Save