smlnj

Output is truncated with #-signs in the REPL

霸气de小男生 提交于 2019-11-27 02:10:23
I wrote a function which works as expected but i don't understand why the output is like that. Function: datatype prop = Atom of string | Not of prop | And of prop*prop | Or of prop*prop; (* XOR = (A And Not B) OR (Not A Or B) *) local fun do_xor (alpha,beta) = Or( And( alpha, Not(beta) ), Or(Not(alpha), beta)) in fun xor (alpha,beta) = do_xor(alpha,beta); end; Test: val result = xor(Atom "a",Atom "b"); Output: val result = Or (And (Atom #,Not #),Or (Not #,Atom #)) : prop This is just an output restriction (yes, it's confusing) - by default the depth of value printouts in the top-level

Why can't I compare reals in Standard ML?

馋奶兔 提交于 2019-11-26 10:02:38
问题 Why doesn\'t 1.0 = 2.0 work? Isn\'t real an equality type? It gives the error: Error: operator and operand don\'t agree [equality type required] operator domain: \'\'Z * \'\'Z operand: real * real in expression: 1.0 = 2.0 Why won\'t reals in patterns work like so? fun fact 0.0 = 1.0 | fact x = x * fact (x - 1.0) It gives the error: Error: syntax error: inserting EQUALOP 回答1: Why doesn't 1.0 = 2.0 work? Isn't real an equality type? No. The type variable ''Z indicates that the operands of =

Output is truncated with #-signs in the REPL

不打扰是莪最后的温柔 提交于 2019-11-26 09:57:11
问题 I wrote a function which works as expected but i don\'t understand why the output is like that. Function: datatype prop = Atom of string | Not of prop | And of prop*prop | Or of prop*prop; (* XOR = (A And Not B) OR (Not A Or B) *) local fun do_xor (alpha,beta) = Or( And( alpha, Not(beta) ), Or(Not(alpha), beta)) in fun xor (alpha,beta) = do_xor(alpha,beta); end; Test: val result = xor(Atom \"a\",Atom \"b\"); Output: val result = Or (And (Atom #,Not #),Or (Not #,Atom #)) : prop 回答1: This is