ml

File seeking with SML Basis

和自甴很熟 提交于 2019-12-05 11:10:55
Is there a way, using the SML Basis library, to open a file at a specific position? That is, use an operating system call to change the position, rather than scan through the file and throw away the data. This is tricky. Unfortunately, seeking isn't directly supported. Moreover, file positions are only transparent for binary files, i.e., those that you have opened with the BinIO structure [1]. For this structure, the corresponding type BinIO.StreamIO.pos is defined to be Position.int , which is some integer type. However, in an SML system that supports the complete I/O stack from the standard

building a lexical analyser using ml-lex

半腔热情 提交于 2019-12-04 11:52:30
I need to create a new instance of a lexer tied to the standard input stream. However, when I type in val lexer = makeLexer( fn n => inputLine( stdIn ) ); I get an error that I don't understand: stdIn:1.5-11.13 Error: operator and operand don't agree [tycon mismatch] operator domain: int -> string operand: int -> string option in expression: ( makeLexer is a function name present in my source code) inputLine returns a string option , and my guess is a string is expected. What you want to do is either have makeLexer take a string option , like so: fun makeLexer NONE = <whatever you want to do

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 Functional language are different from the language implementation point of view

末鹿安然 提交于 2019-12-03 06:53:24
问题 There is the whole new paradigm of "functional programming", which needs a total change of thought patterns compared to procedural programming. It uses higher order functions, purity, monads, etc., which we don't usually see in imperative and object oriented languages. My question is how the implementation of these languages differs from imperative or object oriented languages, with respect to, for example, memory management or internals like pointers etc.. There are functional languages that

How Functional language are different from the language implementation point of view

不羁的心 提交于 2019-12-02 19:29:32
There is the whole new paradigm of "functional programming", which needs a total change of thought patterns compared to procedural programming. It uses higher order functions, purity, monads, etc., which we don't usually see in imperative and object oriented languages. My question is how the implementation of these languages differs from imperative or object oriented languages, with respect to, for example, memory management or internals like pointers etc.. There are functional languages that run on top of the JVM. Does this mean that these languages internally work like the other languages on

A Vision for Making Deep Learning Simple

一笑奈何 提交于 2019-12-02 17:34:32
A Vision for Making Deep Learning Simple When MapReduce was introduced 15 years ago, it showed the world a glimpse into the future. For the first time, engineers at Silicon Valley tech companies could analyze the entire Internet. MapReduce, however, provided low-level APIs that were incredibly difficult to use, and as a result, this “superpower” was a luxury — only a small fraction of highly sophisticated engineers with lots of resources could afford to use it. Today, deep learning has reached its “MapReduce” point: it has demonstrated its potential; it is the “superpower” of Artificial

what is a mutually recursive type?

会有一股神秘感。 提交于 2019-12-02 14:21:34
问题 If in ML, an example of a recursive datatype is: datatype llist = Nil | Node of int * llist What is a mutually recursive datatype and whats an example of it, in ML? 回答1: One such example could be these stupid datatypes. datatype a = A | Ab of b and b = B | Ba of a They make no sense, but they show that it is possible to use the and keyword (just as with functions) to reference something "ahead" which is normally not possible They are mutually (as they both...) recursive (...reference each

Why is the type inferred for my ML function different than I expect?

久未见 提交于 2019-12-02 09:37:54
问题 I made function that's name is maptree . And below is my code: datatype 'a tree = LEAF of 'a | NODE of 'a tree * 'a tree; fun maptree(f, NODE(X, Y)) = NODE(maptree(f, X), maptree(f, Y)) | maptree(f, LEAF(X)) = LEAF(f X); I expected maptree to have the type ('a -> 'a) -> 'a tree -> 'a tree but the type inferred by the compiler is ('a -> 'b) * 'a tree -> 'b tree Why is this happening? 回答1: The Hindley-Milner type-inference algorithm allows you to get more general type than you expected. When

what is a mutually recursive type?

寵の児 提交于 2019-12-02 08:11:01
If in ML, an example of a recursive datatype is: datatype llist = Nil | Node of int * llist What is a mutually recursive datatype and whats an example of it, in ML? One such example could be these stupid datatypes. datatype a = A | Ab of b and b = B | Ba of a They make no sense, but they show that it is possible to use the and keyword (just as with functions) to reference something "ahead" which is normally not possible They are mutually (as they both...) recursive (...reference each other) The standard basic example of mutually recursive data types is a tree and a forest: a forest is a list

How to convert a string to integer list in ocaml?

我与影子孤独终老i 提交于 2019-12-02 04:32:49
I need to pass two list as command line arguments in ocaml. I used the following code to access it in the program. let list1=Sys.argv.(1);; let list2=Sys.argv.(2);; I need to have the list1 and list2 as list of integers. I am getting the error This expression has type string but an expression was expected of type int list while processing. How can I convert that arguments to a list of integers. The arguments are passed in this format [1;2;3;4] [1;5;6;7] Sys.argv.(n) will always be a string. You need to parse the string into a list of integers. You could try something like this: $ ocaml OCaml