Skip to content

Latest commit

 

History

History
81 lines (53 loc) · 1.7 KB

derive-topdown.md

File metadata and controls

81 lines (53 loc) · 1.7 KB

data A a b = A (a,b)

para : {A -> [a,b]} fields : {A -> (a,b)} parameters: {} substitution: {P -> (a,b) -> {a1 -> a, a2 -> b}}

data P a b = M (E a (Px b))
data E x y = L x | R y
data Px z = Px

parameters: { P -> [a,b] }
fields:     { P -> {Either a (Proxy b)} }

for P's fields 

parameters: { P -> [a,b], Either -> [x,y]}
fields:     { P -> {Either a (Proxy b)}  }
substitution: { P -> Either a (Proxy b) -> {x -> a, y -> Proxy b}}
inferred:   {  Either -> {x, y} }

如果所有的field中没有最外层是AppT ConT那么过滤一下应该要去掉没有type var的如果全不存在那么就放到inferred中这是整个算法的basecase然后如果最外层是ConTAppT且这个ConT还是个data type这样就需要递归向下
apply subs to P
refuse id type mapping

parameters: { P -> [a,b], Either -> [x,y]}
fields:     { P -> {a, Proxy b} }
substitution: { (P, NonRec) -> Either a (Proxy b) -> {x -> a, y -> Proxy b} }

make (Name, Rec) map into fix point

inferred { Either -> {VarT x, VarT y} }

P [a,b] {Either a (Proxy b)}

Either [x y] {x, y} {x -> a, y -> Proxy b} this map does not rely on the inference of Either but {x,y} does

subs {Either a (Proxy b)} -> {a, Proxy b} foreach {a, Proxy b} if VarT , keep type family, keep ConT , handle

Proxy [a] {} a -> b {}

a -> {a} Proxy b -> {}

{a} union {} = {a}

data List a = Nil | Cons a (List a)

infer List List [a] {a, List a} List recur {a}

a -> a

如果递归了,就移除,换成映射

data P a b = P b (Rose [] a) data Rose k z = L z | B z (k z)

P [a, b] {b, Rose [] a} Rose [k, z] {z, k z} P : [Sub P Rose {k -> [], z -> a}] {z, k z} -> {a, ([] a)}

data List a = Nil | Cons a (List a)