smlnj

Open file in ML(SMLNJ)

不羁岁月 提交于 2019-11-29 18:11:44
I need to read file in ML (SLMNJ) and save it in some structures. I need to read some data that points to graph declaration: [( 1 , 2 , 13 ),( 2 , 3 , 3 ),( 2 , 4 , 8 ),( 2 , 5 , 4 ),( 3 , 1 , 5 ),( 3 , 4 , 1 ),( 4 , 6 , 5 ),( 5 , 5 , 5 ),( 6 , 4 , 6 )] (first number: name of the node , secend number: name of connected node , third number weight for this mane (each () show one mane ) ) for expamle this is test input how to read file and which structure to save it for reading from file follow this to list of string per line : val infile = "c:/input.txt" ; fun readlist (infile : string) = let

What are the options SOME and NONE in SML?

帅比萌擦擦* 提交于 2019-11-29 14:08:04
I am new to SML (and programming, actually). fun readlist (infile : string) = let val ins = TextIO.openIn infile fun loop ins = case TextIO.inputLine ins of SOME line => line :: loop ins | NONE => [] in loop ins before TextIO.closeIn ins end ; This is a program I encountered here. How do I use SOME and NONE, and how to use 'before'? molbdnilo The option data type is used if there is a possibility of something having no valid value. For instance, fun divide x y = if y == 0 then NONE else SOME (x / y) could be used if you need to handle the special case of division by zero without resorting to

How does the compiler determine types in sml

匆匆过客 提交于 2019-11-29 08:19:04
I've been given the following code and I've been asked to determine the type. exception Break; fn f => fn a => fn b => (f(raise Break) handle Break => if (f a) then a else raise Break) handle Break => if not(f a) then a else b; I know that this function takes in f, a and b and outputs a in all instances so it must be equivelant to: fn f => fn a => fn b => a which has the type: 'a -> 'b -> 'c -> 'b because 'if( f a)' we can derive that 'a must be a function that takes in type 'b and outputs a boolean otherwise it wouldn't work. ('b->bool) -> 'b -> 'c -> 'b re done so 'a is the beginning: ('a-

Increasing the print depth in SML/NJ

家住魔仙堡 提交于 2019-11-29 03:22:17
I'm trying to get SML/NJ to print out a result at the top level without putting # signs everywhere. According to some old docs (and a post to this newsgroup on 2001), it should be possible to use Compiler.Control.Print.printDepth However, on SML/NJ version 110.7, this just gives an error: - Compiler.Control.Print.printDepth := 100; stdIn:1.1-30.8 Error: unbound structure: Control in path Compiler.Control.Print.printDepth You might wan't to be more precise in the future. You could for example give some sample output and a link to where you found the above. If I understand your problem correct,

How to 'fix' the SML/NJ interactive system to use Arrow Keys

倖福魔咒の 提交于 2019-11-29 00:54:22
问题 I'm having some trouble using SML/NJ interactive system, namely, that when I try to use my arrow keys (either left or right to make a correction in the expression I've typed, up to repeat the last expression), my Terminal prints codes. (e.g. ^[[A for up ^[[D for left, etc.). While I can still use the system, it makes it very tedious. I've looked around in Control.Compiler, is there something I'm missing? For whatever its worth, I'm using the Mac Terminal. Thanks ^_^ 回答1: Try this. You can use

SML-NJ, how to compile standalone executable

旧城冷巷雨未停 提交于 2019-11-28 16:20:29
I start to learn Standard ML, and now I try to use Standard ML of New Jersey compiler. Now I can use interactive loop, but how I can compile source file to standalone executable? In C, for example, one can just write $ gcc hello_world.c -o helloworld and then run helloworld binary. I read documentation for SML NJ Compilation Manager, but it don`t have any clear examples. Also, is there another SML compiler (which allow standalone binary creating) available? Both MosML and MLton also have the posibility to create standalone binary files. MosML through mosmlc command and MLton through the mlton

Better display of boolean formulas

假如想象 提交于 2019-11-28 02:05:59
I want to implement a method for showing a propositional formula in SML. The solutions that I found so far was of this type: fun show (Atom a) = a | show (Neg p) = "(~ " ^ show p ^ ")" | show (Conj(p,q)) = "(" ^ show p ^ " & " ^ show q ^ ")" | show (Disj(p,q)) = "(" ^ show p ^ " | " ^ show q ^ ")"; This produces unnecessary braces: ((~p) & (q | r)) when, what I'd like to have is: ~ p & (q | r) I saw, that Haskell has a function (display?) which does this nicely. Can someone help me out a little bit. How should I go about this? If you want to eliminate redundant parentheses, you will need to

How does the compiler determine types in sml

谁都会走 提交于 2019-11-28 01:50:56
问题 I've been given the following code and I've been asked to determine the type. exception Break; fn f => fn a => fn b => (f(raise Break) handle Break => if (f a) then a else raise Break) handle Break => if not(f a) then a else b; I know that this function takes in f, a and b and outputs a in all instances so it must be equivelant to: fn f => fn a => fn b => a which has the type: 'a -> 'b -> 'c -> 'b because 'if( f a)' we can derive that 'a must be a function that takes in type 'b and outputs a

Increasing the print depth in SML/NJ

人走茶凉 提交于 2019-11-27 17:28:28
问题 I'm trying to get SML/NJ to print out a result at the top level without putting # signs everywhere. According to some old docs (and a post to this newsgroup on 2001), it should be possible to use Compiler.Control.Print.printDepth However, on SML/NJ version 110.7, this just gives an error: - Compiler.Control.Print.printDepth := 100; stdIn:1.1-30.8 Error: unbound structure: Control in path Compiler.Control.Print.printDepth 回答1: You might wan't to be more precise in the future. You could for

Better display of boolean formulas

白昼怎懂夜的黑 提交于 2019-11-27 04:52:08
问题 I want to implement a method for showing a propositional formula in SML. The solutions that I found so far was of this type: fun show (Atom a) = a | show (Neg p) = "(~ " ^ show p ^ ")" | show (Conj(p,q)) = "(" ^ show p ^ " & " ^ show q ^ ")" | show (Disj(p,q)) = "(" ^ show p ^ " | " ^ show q ^ ")"; This produces unnecessary braces: ((~p) & (q | r)) when, what I'd like to have is: ~ p & (q | r) I saw, that Haskell has a function (display?) which does this nicely. Can someone help me out a