Created
September 12, 2017 01:29
-
-
Save lisael/d7637678c2b53ceffb80e823a5dde8b4 to your computer and use it in GitHub Desktop.
strange compilator error...
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
type alias Item a = { a | id: Int, path: List Int } | |
type Tree a | |
= Empty | |
| Node (Item a) (List (Tree a)) | |
insert_: Item a -> Tree a -> Tree a | |
insert_ item tree = | |
case tree of | |
Empty -> | |
Node item [] | |
Node i lst -> | |
let | |
newNode = Node item [] | |
in | |
if List.member i.id item.path then | |
case nodeParentId newNode of | |
Nothing -> | |
tree | |
Just id -> | |
if id == i.id then | |
Node i ( lst ++ [newNode] ) | |
else | |
Node i ( List.map (insert_ item) lst ) | |
else | |
tree | |
insert t it = | |
insert_ it t | |
nodeId: Tree a -> Maybe Int | |
nodeId n = | |
case n of | |
Empty -> | |
Nothing | |
Node item _ -> | |
Just item.id | |
nodeParentId: Tree a -> Maybe Int | |
nodeParentId tree = | |
case tree of | |
Empty -> | |
Nothing | |
Node item _ -> | |
List.reverse item.path | |
|> List.drop 1 | |
|> List.head | |
insertAll: Tree a -> (List (Item a)) -> Tree a | |
insertAll tree list = | |
case List.head list of | |
Nothing -> | |
tree | |
Just item -> | |
let | |
tree_ = insert_ item tree | |
in | |
case List.tail list of | |
Nothing -> | |
tree_ | |
Just list_ -> | |
insertAll tree_ list_ | |
type alias Foo | |
= {id: Int, path: (List Int), name: String} | |
insertFoo: Tree Foo -> Foo -> Tree Foo | |
insertFoo t f = | |
insert t f | |
insertFooRev: Foo -> Tree Foo -> Tree Foo | |
insertFooRev f t = | |
insert_ f t |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If
insertFooRev
is commented out, all compiles correctly.The first implementation of
insert
was this ofinsert_
because I wanted to map a partial function at line 25.insert_
is a dirty workaround to be able to use the lib.Did I do anything wrong ? Did I run into a bug in elm ?