Created
March 20, 2017 17:00
-
-
Save zwilias/02b53b09ec5e6fc406be842b2d89ec14 to your computer and use it in GitHub Desktop.
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 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