Trying to represent rose trees
- 主要語言
- Haskell
- 星號
- 952
- 分支
- 50
- PR 合併指標
- 30 天內沒有已合併 PR
描述
Hiya!
I'm trying to represent Rose trees, using `tutd` for now.
```
data Rose a = Node a List (Rose a)
:showexpr relation{tuple{rose Node "a" Empty}}
┌────────────────────┐
│rose::Rose (a::Text)│
├────────────────────┤
│Node "a" Empty │
└────────────────────┘
```
Nice!
But:
```
:showexpr relation{tuple{rose Node "a" (Cons (Node "a" Empty) Empty)}}
ERR: AtomTypeMismatchError TextAtomType (ConstructedAtomType "Rose" (fromList [("a",TextAtomType)]))
```
Hmm... double checking the list is of the right type:
```
:showexpr relation{tuple{list (Cons (Node "a" Empty) Empty)}}
┌──────────────────────────────┐
│list::List (a::Rose (a::Text))│
├──────────────────────────────┤
│Cons (Node "a" Empty) Empty │
└──────────────────────────────┘
```
Looks like it. But wait:
```
:showexpr relation{tuple{node Node "a" (Cons "a" Empty)}}
┌─────────────────────────┐
│node::Rose (a::Text) │
├─────────────────────────┤
│Node "a" (Cons "a" Empty)│
└─────────────────────────┘
```
Now that shouldn't type check, should it?
Ok I'll try another approach, since any way having a list as a value is a [data modelling smell](https://github.com/agentm/project-m36/blame/master/docs/new_datatypes.markdown#L109) isn't it?
```
:showexpr relation{node Text, children relation{}}
┌─────────────────────┬──────────┐
│children::relation {}│node::Text│
└─────────────────────┴──────────┘
```
Too restrictive, but let's try:
```
:showexpr relation{node Text, children relation{}}{tuple{node "a", children relation{}}}
┌─────────────────────┬──────────┐
│children::relation {}│node::Text│
├─────────────────────┼──────────┤
│┌┐ │"a" │
│││ │ │
│└┘ │ │
└─────────────────────┴──────────┘
```
Nice, now we can't do `rose := relation{node Text, children List (rose)}` (or could we?) so let's try to recurse one level manually and see what's up:
```
:showexpr relation{node Text, children relation{node Text, children relation{}}}
┌─────────────────────────────────────────────────────┬──────────┐
│children::relation {node::Text,children::relation {}}│node::Text│
└─────────────────────────────────────────────────────┴──────────┘
```
So far, so good. So a tuple which should fit would be:
```
:type relation{tuple{node "a", children relation{tuple{node "b", children relation{}}}}}
┌─────────────────────────────────────────────────────┬──────────┐
│children::relation {children::relation {},node::Text}│node::Text│
└─────────────────────────────────────────────────────┴──────────┘
```
But tying these to together doesn't work! 😢
```
:showexpr relation{node Text, children relation{node Text, children relation{}}}{tuple{node "a", children relation{tuple{node "b", children relation{}}}}}
ERR: AtomTypeMismatchError (RelationAtomType [Attribute "node" TextAtomType,Attribute "children" (RelationAtomType [])]) (RelationAtomType [Attribute "children" (RelationAtomType []),Attribute "node" TextAtomType])
```
貢獻指南
這個儲存庫沒有索引到貢獻指南
評估
這個 Issue 還沒有評估資料。