smlnj

How to import from another file in SML, with a path relative to the importer?

拈花ヽ惹草 提交于 2019-12-10 15:56:22
问题 I'm using SML/NJ, and I need to use a set of functions that are in a certain file f1.sml inside another file f2.sml . However, I'm not running f2.sml directly, rather, I'm importing it from somewhere else. If I use the use command in f2.sml with the path to f1.sml relative to f2.sml perspective, by the time I import f2.sml , it will look for the supplied path from the running script perspective. I cannot use absolute paths, and I'd like not to merge the two files contents. Sorry if this is a

What do questions marks mean in Standard ML types?

旧街凉风 提交于 2019-12-10 13:28:38
问题 For instance: vagrant@precise32:/vagrant$ rlwrap sml Standard ML of New Jersey v110.76 [built: Mon May 12 17:11:57 2014] - TextIO.StreamIO.inputLine ; [autoloading] [library $SMLNJ-BASIS/basis.cm is stable] [autoloading done] val it = fn : ?.TextIO.instream -> (string * ?.TextIO.instream) option - val s = TextIO.openIn "README.md" ; val s = - : TextIO.instream - TextIO.StreamIO.inputLine s ; stdIn:3.1-3.28 Error: operator and operand don't agree [tycon mismatch] operator domain: ?.TextIO

Function which applies its argument to itself?

烈酒焚心 提交于 2019-12-10 12:58:37
问题 Consider the following SML function: fn x => x x This produces the following error (Standard ML of New Jersey v110.72): stdIn:1.9-1.12 Error: operator is not a function [circularity] operator: 'Z in expression: x x I can sort of see why this isn't allowed -- for one, I'm not really sure how to write down what its type would be -- but it's not completely nonsensical; for instance, I could pass the identity function to it and get it back. Is there a name for this function? (Is there a way to

How can I define a heteregeneous list datatype?

て烟熏妆下的殇ゞ 提交于 2019-12-10 11:55:57
问题 I am just starting to learn SML and having issues. I want to define a datatype, for a list that is not homogeneous. Take for example val a = [1,[2,4,3],5,[2,6]] I have made this datatype datatype 'a MulList = List of 'a multiList list | E of 'a; but I get the following error /tmp/emacs-region29207RwC:8.34-8.43 Error: unbound type constructor: multiList uncaught exception Error raised at: ../compiler/TopLevel/interact/evalloop.sml:66.19-66.27 ../compiler/TopLevel/interact/evalloop.sml:44.55 ..

ML assignment operation

时光怂恿深爱的人放手 提交于 2019-12-08 12:38:39
问题 everyone, what is difference between the following assignments in ML, val n = 5; and n := 1; 回答1: The former is a declaration of a new, immutable variable. The latter is how you re-assign the value of a reference cell. 来源: https://stackoverflow.com/questions/5168889/ml-assignment-operation

in smlnj how do you convert “string option” to “string”?

僤鯓⒐⒋嵵緔 提交于 2019-12-07 12:24:36
问题 Please help I have no idea how what a string option does. is it possible to convert string option to a string? 回答1: As already pointed out you could use pattern matching to get the desired result. So, something like this: fun foo(NONE) = "" | foo(SOME a) = a; But you could spare the trouble and use Option.valOf function from SML library instead by just doing: Option.valOf(SOME "my string"); (Or just valOf(SOME "my string"); as newacct pointed out in the comments.) 回答2: The "option" type in ML

How can I customize the SML/NJ interactive loop?

↘锁芯ラ 提交于 2019-12-07 12:04:04
问题 I'm new to Standard ML and I'm trying to get my head around the SML/NJ runtime environment. I want to adapt it to my needs. Specifically, I want to: Use IntInf by default Prevent it from truncating strings and IntInf to 70 characters. Here's what I've found in my 8+ hours reading documentation and experimenting. I can overload IntInf on top of int with the command open IntInf; I can control how many characters in a string are displayed with the variable Control.Print.stringDepth. For example,

What do “continuations” mean in functional programming?(Specfically SML)

≯℡__Kan透↙ 提交于 2019-12-07 09:18:31
问题 I have read a lot about continuations and a very common definition I saw is, it returns the control state. I am taking a functional programming course taught in SML. Our professor defined continuations to be: "What keeps track of what we still have to do" ; "Gives us control of the call stack" A lot of his examples revolve around trees. Before this chapter, we did tail recursion. I understand that tail recursion lets go of the stack to hold the recursively called functions by having an

Polymorphic function as return value and value restriction in SML

我们两清 提交于 2019-12-07 07:09:55
问题 Basically, I want to have a function to return a polymorphic function, some thing like this: fun foo () = fn x => x So the foo function takes in a value of type unit and returns a polymorphic identity function and the compiler is happy with that, it gives me: val foo = fn : unit -> 'a -> 'a but once I actually call the foo function, the return value is not what I expected val it = fn : ?.X1 -> ?.X2 Can't generalize because of value restriction it says, any help? thanks in advance 回答1: For

Passing command-line arguments to an SML script

*爱你&永不变心* 提交于 2019-12-07 02:51:55
问题 How do I go about passing command-line arguments to an SML script? I'm aware that there is a CommandLine.arguments() function of the right type ( unit -> string list ), but invoking the interpreter like so: $ sml script_name.sml an_argument another_one doesn't give me anything. Pointers? 回答1: Try this. (* arg.sml *) val args = CommandLine.arguments() fun sum l = foldr op+ 0 (map (valOf o Int.fromString) l) val _ = print ("size: " ^ Int.toString (length args) ^ "\n") val _ = print ("sum: " ^