sml

How to do bitwise AND in SML/NJ?

会有一股神秘感。 提交于 2019-12-01 20:41: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. 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/35742341/how-to-do-bitwise-and-in-sml-nj

Multiple Patterns in 1 case

試著忘記壹切 提交于 2019-12-01 18:37:32
In SML, is it possible for you to have multiple patterns in one case statement? For example, I have 4 arithmetic operators express in string, "+", "-", "*", "/" and I want to print "PLUS MINUS" of it is "+" or "-" and "MULT DIV" if it is "*" or "/" . TL;DR: Is there somewhere I can simplify the following to use less cases? case str of "+" => print("PLUS MINUS") | "-" => print("PLUS MINUS") | "*" => print("MULT DIV") | "/" => print("MULT DIV") Given that you've tagged your question with the smlnj tag, then yes, SML/NJ supports this kind of patterns. They call it or-patterns and it looks like

Horner's rule for two-variable polynomial

末鹿安然 提交于 2019-12-01 18:01:36
Horner's rule is used to simplify the process of evaluating a polynomial at specific variable values. https://rosettacode.org/wiki/Horner%27s_rule_for_polynomial_evaluation#Standard_ML I've easily applied the method using SML, to a one variable polynomial, represented as an int list: fun horner coeffList x = foldr (fn (a, b) => a + b * x) (0.0) coeffList This works fine. We can then call it using: - val test = horner [1.0, 2.0, 3.0] 2.0; > val test = 17.0 : real Where [1.0, 2.0, 3.0] is the list representing the polynomial coefficients, 2.0 is the value of the variable x, and 17.0 is the

Swap pairs of elements in a list using pattern matching

Deadly 提交于 2019-12-01 13:49:07
问题 I need to use pattern matching techniques, in order to recursively swap every pair of elements in a list. So, [1, 2, 3, 4, 5] would return [2, 1, 4, 3, 5] . Two things I have found: List.length : to return the length. Which is helpful to deal with even/odd lists. List.nth : to return a value at the designated spot in the list. drop.(list, i) : to return the values after the first i elements are dropped. Using those three things, I can sort of figure out some recursion methods, but I don't

See SML full list

大憨熊 提交于 2019-12-01 11:14:12
Is there any way to print full list using SML? Usually what happen is in SML when I have too many elements it prints first few elements separated by "," and then it omits the rest of the list with ... but I want to see the full list. Is there any way to do that? val a =[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,18,19,20] then If i write on REPL a it returns something like: a=[1,2,3,4,5,...] Assuming that you are using SML/NJ. What you wan't to customize is the reference values in Control.Print . In this case you wan't to change the value of printLength to something larger, for example

Suppress “val it” output in Standard ML

二次信任 提交于 2019-12-01 03:40:28
I'm writing a "script" in Standard ML (SML/NJ) that sets up the interactive environment to my liking. The last thing the script does is print out a message indicating everything went smoothly. Essentially, the last line is this: print "SML is ready.\n"; When I run the script, all goes well but the SML interpreter displays the return value from the print function. SML is ready. val it = () : unit - Since I'm merely printing something to the screen, how can I suppress the "val it = () : unit" output so that all I see is the "SML is ready" message followed by the interpreter prompt? To surpress

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

断了今生、忘了曾经 提交于 2019-12-01 00:34:46
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. 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_profile --go to terminal and type sml. I personally use sml mode for emacs. Add the following to your .emacs

What does this function signature mean in sml?

核能气质少年 提交于 2019-12-01 00:23:09
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, aren't you only allowed one parameter in sml? It means that lp is a function that takes 2 parameters,

How to disable SMLNJ warnings?

两盒软妹~` 提交于 2019-11-30 17:29:48
问题 I'm trying to write command line scripts, but SML's warnings obfuscate the interface. The docs say to use: Compiler.Control.printWarnings := false; But SMLNJ has since renamed these to: Control.printWarnings := false; Which actually produces even more printouts. Example: $ cat hello.sml print "Hello World!\n"; OS.Process.exit(OS.Process.success); $ sml hello.sml Standard ML of New Jersey v110.72 [built: Mon Nov 14 17:30:10 2011] [opening hello.sml] Hello World! val it = () : unit [autoloading

If SML.NET had functors why can't F#?

感情迁移 提交于 2019-11-30 10:35:29
问题 This question started out from My translating of "ML for the Working Programmer" (WorldCat) by L. C. PAULSON to F# which uses functors for the examples. Eventual desire to translate "Purely Functional Data Structures" (WorldCat) by Chris Okasaki which uses functors. Reading "CATEGORIES TYPES AND STRUCTURES - An Introduction to Category Theory for the working computer scientist" (WorldCat) by Andrea Asperti and Giuseppe Longo. Not understanding it all, mostly the category theory. SML.NET can