smlnj

When to use semicolons in SML?

冷暖自知 提交于 2019-12-03 23:36:56
I know that semicolons are used as terminators in REPL. But I'm confused about when to use them in a source file. For example it is not necessary after val x = 1 . But if I omit it after use "foo.sml" , the compiler will complain about it. Then, what are the rules on using semicolons? Semicolons are used for a number of syntactic entities in SML. They are normally used to create sequences of, e.g., expressions or declarations. Here's a link to the SML grammar: http://www.mpi-sws.org/~rossberg/sml.html In your case, you are interested in the semicolon for declarations (the dec class). Note that

How do I install a working version of Standard ML on Mac?

我是研究僧i 提交于 2019-12-03 22:08:11
问题 I'm using Mac OSX 10.7.5 and I can't seem to get download a working Standard ML compiler with a REPL available. Is this supposed to be so difficult? Is there a best ML that I should be downloading. I've tried SML/NJ and MLton to no avail. 回答1: I did the following: --download appropriate(for your operating system) .dmg file from http://www.smlnj.org/dist/working/110.75/ --in your ~/.bash_profile: export PATH="$PATH:/usr/local/smlnj-110.75/bin" --run your bash_profile by doing source .bash

Curried anonymous function in SML

六月ゝ 毕业季﹏ 提交于 2019-12-03 15:11:46
问题 I have the function below and it works: (fn x => x * 2) 2; but this one doesn't work: (fn x y => x + y ) 2 3; Can anyone tell me why? Or give me some hint to get it to work? 回答1: (fn x => fn y => x+y) 2 3; works. fn simply doesn't have the same syntactic sugar to define curried functions that fun has. 回答2: In Standard ML, a function can have only one argument , so use (fn (x,y) => x + y) (2,3) and the type is fn: int * int -> int in this time (x,y) and (2,3) is a list structure, 回答3: The

Curried anonymous function in SML

倾然丶 夕夏残阳落幕 提交于 2019-12-03 04:54:40
I have the function below and it works: (fn x => x * 2) 2; but this one doesn't work: (fn x y => x + y ) 2 3; Can anyone tell me why? Or give me some hint to get it to work? (fn x => fn y => x+y) 2 3; works. fn simply doesn't have the same syntactic sugar to define curried functions that fun has. In Standard ML, a function can have only one argument , so use (fn (x,y) => x + y) (2,3) and the type is fn: int * int -> int in this time (x,y) and (2,3) is a list structure, The answers posted above are correct. SML functions take only one argument. As a result, SML functions can have only one of

Horner's algorithm in SML? [closed]

▼魔方 西西 提交于 2019-12-02 23:52:48
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I am trying to implement Horner's algorithm in SML. fun horner(lst1:real list,x:real) = let val i = ref 1 val result = ref (List.last(lst1)) in if (lst1) = ([]:real list) then 0.0 else while (!i <= length(lst1)-1) do (result:=!result*x+List.nth(lst1,length(lst1)-(!i)-1); i := !i+1); !result end; Takes on a{n},

SMLNJ expand # in output

有些话、适合烂在心里 提交于 2019-12-02 23:46:52
问题 I have the following: val it = DATAX ("hello",DATAX ("world",DATAX #,DATAX #),... Is there a way to make the SMLNJ interpreter expand "#" so that I can see what the exact data is? Thanks! 回答1: Ok. I found an answer: http://www.cs.cmu.edu/~me/212/environment.html When SML/NJ prints a data structure, it prints that data structure only to a certain depth. Beneath that depth it prints a # instead. This is generally a good thing, since data structures can be very large (and even cyclic). However,

Horner's algorithm in SML? [closed]

懵懂的女人 提交于 2019-12-02 13:43:13
I am trying to implement Horner's algorithm in SML. fun horner(lst1:real list,x:real) = let val i = ref 1 val result = ref (List.last(lst1)) in if (lst1) = ([]:real list) then 0.0 else while (!i <= length(lst1)-1) do (result:=!result*x+List.nth(lst1,length(lst1)-(!i)-1); i := !i+1); !result end; Takes on a{n}, the coeff of x^n, as its initial result, then using horner's evaluates a polynomial. Evaluates as ((a{n}*x+a{n-1})*x+a{n-2})..The list contains the coefficients of the polynomial. Problem is the "if lst1 = []....else" part. Employing only the while loop makes the program run well. But I

SMLNJ expand # in output

大憨熊 提交于 2019-12-02 08:17:55
I have the following: val it = DATAX ("hello",DATAX ("world",DATAX #,DATAX #),... Is there a way to make the SMLNJ interpreter expand "#" so that I can see what the exact data is? Thanks! Ok. I found an answer: http://www.cs.cmu.edu/~me/212/environment.html When SML/NJ prints a data structure, it prints that data structure only to a certain depth. Beneath that depth it prints a # instead. This is generally a good thing, since data structures can be very large (and even cyclic). However, the default depth to which SML/NJ prints data structures is 5, which is usually not enough. You can adjust

Looping over lines of a text file in SML/NJ

泪湿孤枕 提交于 2019-12-02 04:13:35
I have this SML/NJ code that reads a single line from a text file and then it will return a list for me, but I am having trouble making it do the same thing to every single line and stop when there are no more lines. Can anyone please help me by giving me a looping sample here? fun readlist(infile : string) = let val ins = TextIO.openIn infile val list = [] fun listing() = [TextIO.inputLine ins]::list; in listing() end How about something like this: fun readlist (infile : string) = let val ins = TextIO.openIn infile fun loop ins = case TextIO.inputLine ins of SOME line => line :: loop ins |

SML not detecting OS on OS X Mavericks

旧城冷巷雨未停 提交于 2019-12-01 23:03:08
I could not run SMLNJ on Mavericks It shows me the error sml: unable to determine architecture/operating system I also looked in /usr/local/smlnj/config/_arch-n-opsys file and Mavericks is mentioned there. 13*) OPSYS=darwin; HEAP_OPSYS=darwin ;; # MacOS X 10.9 Mavericks Can some one help me on this? You can use this .pkg file to reinstall the SML and see if the problem happens again. 来源: https://stackoverflow.com/questions/20009628/sml-not-detecting-os-on-os-x-mavericks