X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=docs%2Fsphinx_docs%2F_build%2Fhtml%2Fnotebooks%2FTypeChecking.html;h=5f201cef60ce918640f7b509dffadadc6947434b;hb=1b193b19243a3aa23f74b6ecbcfd3f217bf66907;hp=9c4d5bbd48075f689c9507c8d8659dfc77b2f032;hpb=eeda5044ade9a2d601cd25211d1ab0c3a35691de;p=joypy%2FThun.git diff --git a/docs/sphinx_docs/_build/html/notebooks/TypeChecking.html b/docs/sphinx_docs/_build/html/notebooks/TypeChecking.html index 9c4d5bb..5f201ce 100644 --- a/docs/sphinx_docs/_build/html/notebooks/TypeChecking.html +++ b/docs/sphinx_docs/_build/html/notebooks/TypeChecking.html @@ -35,33 +35,33 @@

Type Checking¶

-
import logging, sys
+
import logging, sys
 
-logging.basicConfig(
-  format='%(message)s',
-  stream=sys.stdout,
-  level=logging.INFO,
-  )
+logging.basicConfig(
+  format='%(message)s',
+  stream=sys.stdout,
+  level=logging.INFO,
+  )
 
-
from joy.utils.types import (
-    doc_from_stack_effect,
-    infer,
-    reify,
-    unify,
-    FUNCTIONS,
-    JoyTypeError,
-)
+
from joy.utils.types import (
+    doc_from_stack_effect,
+    infer,
+    reify,
+    unify,
+    FUNCTIONS,
+    JoyTypeError,
+)
 
-
D = FUNCTIONS.copy()
-del D['product']
-globals().update(D)
+
D = FUNCTIONS.copy()
+del D['product']
+globals().update(D)
 

An Example¶

-
fi, fo = infer(pop, swap, rolldown, rrest, ccons)[0]
+
fi, fo = infer(pop, swap, rolldown, rrest, ccons)[0]
 
25 (--) ∘ pop swap rolldown rrest ccons
@@ -72,32 +72,32 @@ globals().update(D)
 40 ([a4 a5 ...1] a3 a2 a1 -- [a2 a3 ...1]) ∘
 
-
print doc_from_stack_effect(fi, fo)
+
print doc_from_stack_effect(fi, fo)
 
([a4 a5 ...1] a3 a2 a1 -- [a2 a3 ...1])
 
-
from joy.parser import text_to_expression
-from joy.utils.stack import stack_to_string
+
from joy.parser import text_to_expression
+from joy.utils.stack import stack_to_string
 
-
e = text_to_expression('0 1 2 [3 4]')  # reverse order
-print stack_to_string(e)
+
e = text_to_expression('0 1 2 [3 4]')  # reverse order
+print stack_to_string(e)
 
[3 4] 2 1 0
 
-
u = unify(e, fi)[0]
-u
+
u = unify(e, fi)[0]
+u
 
{a1: 0, a2: 1, a3: 2, a4: 3, a5: 4, s2: (), s1: ()}
 
-
g = reify(u, (fi, fo))
-print doc_from_stack_effect(*g)
+
g = reify(u, (fi, fo))
+print doc_from_stack_effect(*g)
 
(... [3 4 ] 2 1 0 -- ... [1 2 ])
@@ -106,18 +106,18 @@ print doc_from_stack_effect(*g)
 

Unification Works “in Reverse”¶

-
e = text_to_expression('[2 3]')
+
e = text_to_expression('[2 3]')
 
-
u = unify(e, fo)[0]  # output side, not input side
-u
+
u = unify(e, fo)[0]  # output side, not input side
+u
 
{a2: 2, a3: 3, s2: (), s1: ()}
 
-
g = reify(u, (fi, fo))
-print doc_from_stack_effect(*g)
+
g = reify(u, (fi, fo))
+print doc_from_stack_effect(*g)
 
(... [a4 a5 ] 3 2 a1 -- ... [2 3 ])
@@ -126,7 +126,7 @@ print doc_from_stack_effect(*g)
 

Failing a Check¶

-
fi, fo = infer(dup, mul)[0]
+
fi, fo = infer(dup, mul)[0]
 
25 (--) ∘ dup mul
@@ -135,17 +135,17 @@ print doc_from_stack_effect(*g)
 31 (i1 -- i2) ∘
 
-
e = text_to_expression('"two"')
-print stack_to_string(e)
+
e = text_to_expression('"two"')
+print stack_to_string(e)
 
'two'
 
-
try:
-    unify(e, fi)
-except JoyTypeError, err:
-    print err
+
try:
+    unify(e, fi)
+except JoyTypeError, err:
+    print err
 
Cannot unify 'two' and f1.