ml

Value of bindings in SML?

懵懂的女人 提交于 2019-12-02 00:50:24
问题 can someone please explain why is "ans" is bound to value of 16 in here after evaluation - this is a correct answer? I thought the answer 3 since we're calling function f and sending values 1 and 2 as function f doesn't also see the values 5 and 10 but I guess I am wrong. val x = 1 val y = 2 val f = fn y => x + y val x = 5 val y = 10 val ans = f x + y 回答1: What you are seeing is sometimes called lexical scoping . The function f was defined in the scope of a certain binding for x , that scope

N-ary tuples vs pairs

萝らか妹 提交于 2019-12-01 16:12:21
In Ocaml, tuples with different arities have different type and value constructors: # let a = (1, 2, 3);; val a : int * int * int = (1, 2, 3) # let b = (1, (2, 3));; val b : int * (int * int) = (1, (2, 3)) Note that second example (b) is more flexible than first (a) because "tail" of b - (2, 3) - itself is valid value: # let (_, c) = b;; val c : int * int = (2, 3) # let d = snd b;; val d : int * int = (2, 3) What is the reason to not parse "(1, 2, 3)" as "(1, (2, 3))" and instead introduce infinite (or, even worse, finite) amount of new type and value constructors for different arities? What

N-ary tuples vs pairs

喜你入骨 提交于 2019-12-01 15:10:47
问题 In Ocaml, tuples with different arities have different type and value constructors: # let a = (1, 2, 3);; val a : int * int * int = (1, 2, 3) # let b = (1, (2, 3));; val b : int * (int * int) = (1, (2, 3)) Note that second example (b) is more flexible than first (a) because "tail" of b - (2, 3) - itself is valid value: # let (_, c) = b;; val c : int * int = (2, 3) # let d = snd b;; val d : int * int = (2, 3) What is the reason to not parse "(1, 2, 3)" as "(1, (2, 3))" and instead introduce

Does SML (Poly) have a CL-like REPL?

一世执手 提交于 2019-12-01 07:34:47
Here's a quote from Ron Garret's "Lisping at JPL": "Debugging a program running on a $100M piece of hardware that is 100 million miles away is an interesting experience. Having a read-eval-print loop running on the spacecraft proved invaluable in finding and fixing the problem." As a beginner trying to decide where to jump in, I am leaning towards ML because a former prof raved about and I'm finding many books that integrate Lambda Calculus discussions with ML and ML looks fairly sane. (I'm eventually going to teach this.) So, does ML have a REPL where, like Lisp, you can just "add more code"

Does SML (Poly) have a CL-like REPL?

梦想与她 提交于 2019-12-01 04:08:08
问题 Here's a quote from Ron Garret's "Lisping at JPL": "Debugging a program running on a $100M piece of hardware that is 100 million miles away is an interesting experience. Having a read-eval-print loop running on the spacecraft proved invaluable in finding and fixing the problem." As a beginner trying to decide where to jump in, I am leaning towards ML because a former prof raved about and I'm finding many books that integrate Lambda Calculus discussions with ML and ML looks fairly sane. (I'm

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

Open file in ML(SMLNJ)

旧时模样 提交于 2019-11-30 09:54:00
问题 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 回答1: for reading from file

Standard ML functor examples

假如想象 提交于 2019-11-30 06:58:16
问题 Functors in Standard ML are related to the module system and can generate structures based on other structures. An example of a functor generating list combinators for various types of lists is given below, but this example has a problem: The various types of lists all have advantages -- for example, lazy lists can be infinitely long, and concantenation lists have a O(1) concat operator. But when all of these list types conform to the same signature, the functor can only use their general

Which English tutorial would you advise to learn OCaml? [closed]

非 Y 不嫁゛ 提交于 2019-11-29 22:25:21
I want to advertise OCaml to beginners, and I am looking for good tutorials in English; not that you have only heard of, but that you have actually tried and found useful... I quite like the book Developing Applications With Objective Caml -- I guess the title should be updated to mirror the 'OCaml' naming decision. It is old and therefore slightly out-of-date, but on only minor aspects -- eg., it presents the stream syntax as belonging to the core language, but it is now outsourced as a Camlp4 extension. The book is surprisingly complete, and there is a lot of meat already in the chapters 2,

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