phil_algs / Languages /docs8.txt
luciangreen's picture
Upload 1424 files
557a17a verified
# Type Statements
* Functions may have strong types, which check inputted values when calling a function and check all values when exiting a function. So far, any type statement with the name and arity of the function may match data for a call to that function.
* The user may optionally enter types after the query. The following type statement tests number, string and predicate name types.
* Note: Mode statements, described in the next section, are required after Type Statements.
* Types with lists (0-infinite repeats of type statements) are written inside {}. There may be nested curly brackets.
* Type Statements may be recursive (see test 23 in <a href="https://github.com/luciangreen/listprologinterpreter/blob/master/lpiverify4_types.pl">lpiverify4_types.pl</a>), i.e. they may repeat until triggering the base case:
test_types_cases(23,`[[n,connect_cliques],[[["a",1],[1,2],[2,"b"]],[["a",3],[3,4],[4,"b"]],[v,output]]]`,
`[
[[n,connect_cliques],[[t,list2],[t,list2],[t,list2]]],
[[t,item],[[t,number]]],
[[t,item],[[t,string]]],
[[t,list2],[{[t,item]}]],
[[t,list2],[{[t,list2]}]]
]`,
`[[[n,connect_cliques],[input,input,output]]]`,
`[[[n,connect_cliques],[[v,a],[v,b],[v,c]],":-",[[[n,append],[[v,a],[v,b],[v,c]]]]]]`,
`[[[[v,output],[["a",1],[1,2],[2,"b"],["a",3],[3,4],[4,"b"]]]]]`).