¡Cosas divertidas!
Primero inventó un tipo genérico para ListaSuma: x -> y
y obtener las ecuaciones simples: t(lst) = x
; t(match ...) = y
Si ahora se añade la ecuación: t(lst) = [a]
debido (match lst with [] ...)
Entonces la ecuación: b = t(0) = Int
; y = b
Desde 0 es un posible resultado del partido: c = t(match lst with ...) = b
Desde el segundo patrón: t(lst) = [d]
; t(hd) = e
; t(tl) = f
; f = [e]
; t(lst) = t(tl)
; t(lst) = [t(hd)]
Guess un tipo (un tipo genérico) para hd
: g = t(hd)
; e = g
entonces necesitamos un tipo de sumList
, por lo que sólo obtendrá un tipo de función de sentido por ahora: h -> i = t(sumList)
Así que ahora sabemos: h = f
; t(sumList tl) = i
Luego de la adición, se obtiene: Addable g
; Addable i
; g = i
; t(hd + sumList tl) = g
Ahora podemos empezar la unificación:
t(lst) = t(tl)
=>
[a] = f = [e]
=>
a = e
t(lst) = x = [a] = f = [e]
; h = t(tl) = x
t(hd) = g = i
/\
i = y
=>
y = t(hd)
x = t(lst) = [t(hd)]
/\
t(hd) = y
=>
x = [y]
y = b = Int
/\
x = [y]
=>
x = [Int]
=>
t(sumList) = [Int] -> Int
Me salté algunos pasos triviales, pero creo que puedes ver cómo funciona.
Creo que esto podría pertenecer a otro sitio SE, pero no estoy seguro de cuál :) –
Si es así, ¿me puede dar un enlace a eso? Seria útil. – riship89
Bueno, creo que pertenece a Theo CS, pero no creo que lo acepten.A menos que aparezca un moderador inteligente, supongo que esto permanecerá aquí :) –