smlnj

I want to make function maptree with standard ML

↘锁芯ラ 提交于 2019-12-23 18:23:02
问题 I want to make function maptree with standard ML. If function f(x) = x + 1; then maptree(f, NODE(NODE(LEAF 1,LEAF 2),LEAF 3)); should make result NODE(NODE(LEAF 2,LEAF 3),LEAF 4)) I write the code like below. datatype 'a tree = LEAF of 'a | NODE of 'a tree * 'a tree; fun f(x) = x + 1; fun maptree(f, NODE(X, Y)) = NODE(maptree(f, X), maptree(f, Y)) | maptree(f, LEAF(X)) = LEAF(f X); but when I execute this code like this maptree(f, (NODE(NODE(LEAF 1,LEAF 2),LEAF 3))); result is not I want to

unresolved flex record (need to know the names of ALL the fields in this context)

守給你的承諾、 提交于 2019-12-22 06:38:13
问题 I've been trying to create a function with a tuple-list as an argument but I keep getting the error: "unresolved flex record (need to know the names of ALL the fields in this context)" My code is: fun convert d = ( (map (#1) d) , (map (#2) d) ); This is basicaly trying to convert a list of pairs into a pair of lists.I've also tried to declare the type of d as :('a * 'b) list but that resulted in even more errors. I assume that this has something to do with the unknown size of the tupple and

Unable to determine OS

五迷三道 提交于 2019-12-22 01:35:13
问题 When I go on terminal (i installed smlnj) and i type sml it gives me the error sml: unable to determine architecture/operating system . What does this mean??? I installed sml like this at this website, but I'm not sure -- are the instructions wrong? 回答1: If you're using OSX 10.8 or later ( uname -r gives you something starting with 12 or higher), SML/NJ pre 110.75 doesn't work too well without some extra tweaking. It's a known issue that can be fixed by adding the 10.8 choice (see the 12 line

BigInt for Standard ML/NJ

半城伤御伤魂 提交于 2019-12-21 18:02:54
问题 Is there a Java BigInt equivalent for Standard ML? The normal int type throws an exception when it overflows. 回答1: Yes, see the IntInf structure. 回答2: The official SML'97 standard basis library introduces a zoo of structures like Int, IntInf, Int32, Int64, LargeInt etc. To actually use them in practice to make things work as expected, and make them work efficiently, you need to look closely at the SML implementation at hand. One family of implementations imitates the memory layout of C and

Looping over lines of a text file in SML/NJ

谁说我不能喝 提交于 2019-12-20 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 回答1: How about something like this: fun readlist (infile : string) = let

SML not detecting OS on OS X Mavericks

佐手、 提交于 2019-12-20 02:58:17
问题 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? 回答1: 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

How to do bitwise AND in SML/NJ?

女生的网名这么多〃 提交于 2019-12-20 01:09:30
问题 Need it for a program I'm writing (repeated squaring to comput x^n). I can't seem to find the syntax for it, or if it is even supported. 回答1: They're available within the Word8 and Word structures. let open Word8 infix andb orb xorb notb << >> ~>> in print (Word8.fmt StringCvt.BIN 0wxF) (* 1111 *) ; print "\n" ; print (Word8.fmt StringCvt.BIN 0wxA) (* 1010 *) ; print "\n" ; print (Word8.fmt StringCvt.BIN (0wxF andb 0wxA)) (* 1010 *) ; print "\n" end 来源: https://stackoverflow.com/questions

SML How to define proper option

跟風遠走 提交于 2019-12-19 10:22:05
问题 Why doesn't the following code doesn't work? fun sum_list xs = case xs of [] => NONE | x::xs' => SOME (x+sum_list xs') This code works well when Instead of NONE it is zero and when I remove SOME. I know that for sum of an empty list zero is the reasonable answer. But why does the following example fails? Update: Made it work by following Diego's Answer: fun sum_list xs = case xs of [] => NONE | x => let fun slist x = case x of [] => 0 | x::xs' => x + slist xs' in SOME (slist x) end 回答1: The

What does this function signature mean in sml?

自作多情 提交于 2019-12-19 04:35:28
问题 I'm looking through some notes that my professor gave regarding the language SML and one of the functions looks like this: fun max gt = let fun lp curr [] = curr | lp curr (a::l) = if gt(a,curr) then lp a l else lp curr l in lp end Could someone help explain what this is doing? The thing that I am most confused about is the line: let fun lp curr [] = curr What exactly does this mean? As far as I can tell there is a function called lp but what does the curr [] mean? Are these arguments? If so,

SML-NJ, how to compile standalone executable

对着背影说爱祢 提交于 2019-12-17 21:44:01
问题 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? 回答1: Both MosML and MLton also have