Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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