Skip to content

Instantly share code, notes, and snippets.

@zwilias
Created March 20, 2017 17:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zwilias/02b53b09ec5e6fc406be842b2d89ec14 to your computer and use it in GitHub Desktop.
Save zwilias/02b53b09ec5e6fc406be842b2d89ec14 to your computer and use it in GitHub Desktop.
module Test exposing (..)
{-| A binary search tree will often look roughly like this.
Every node will either be the `Empty` node, or a node with
a key, a value and left and right children. In this case, we
also have an extra `Int` to keep track of the height, but
that's not relevant to the example at hand.
-}
type Dict k v
= Empty
| Node Int k v (Dict k v) (Dict k v)
foldl : (k -> v -> a -> a) -> a -> Dict k v -> a
foldl op acc dict =
case dict of
Empty ->
acc
Node _ key val left right ->
foldl op acc left
|> op key val
|> (\acc -> foldl op acc right)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment