sml

SMLNJ want to remove “val it = () : unit” from every print statement execution

余生长醉 提交于 2019-12-10 21:07:46
问题 I am writing sml programs which run on SML/NJ and MLton (not interactive). When I use print statements in the the sml file, SML/NJ always adds val it = () : unit to the output, which clutters up the output. MLton does not do this. Is there a way to remove this output? I have tried CM_VERBOSE=false, which did not help. Running SML/NJ v110.73. 回答1: Without examples of the code that produces this, it is a bit hard to help, however it seems that your "issues" are somewhat related to this question

PolyML Functions and Types

北战南征 提交于 2019-12-10 20:08:16
问题 [...] a pair of functions tofun : int -> ('a -> 'a) and fromfun : ('a -> 'a) -> int such that (fromfun o tofun) n evaluates to n for every n : int . Anyone able to explain to me what this is actually asking for? I'm looking for more of an explanation of that than an actual solution to this. 回答1: What this is asking for is: 1) A higher-order function tofun which when given an integer returns a polymorphic function, one which has type 'a->'a , meaning that it can be applied to values of any

How can I parse String to (int * int) tuple in SML?

做~自己de王妃 提交于 2019-12-10 19:43:17
问题 I have a string something like this "3,4\r\n" , and I want to convert them into a tuple i.e (3,4) . How can we achieve this in SML ? The reason why I'm getting a string value is because I'm reading a file which returns strings like that. 回答1: You need a simple parser to achieve that. An appropriate function to parse integers is already available in the library as Int.scan (along with friends for other types), but you have to write the rest yourself. For example: (* scanLine : (char, 's)

Funky indentation in SML mode

拈花ヽ惹草 提交于 2019-12-10 18:32:46
问题 I installed SML Mode in Emacs and the indentation is messed up. I disabled all my .emacs customizations, but that didn't make any difference. At the end of each line in the code below, I used C-j , which is mapped to newline-and-indent . If I highlight everything and reindent ( C-M-\ ), the result makes more sense: I'm using Emacs 24.1.1 and SML Mode 6.2 on Ubuntu 12.10. What should I do? 回答1: Don't use newline-and-indent . You can use reindent-then-new-and-indent or electric-indent-mode

ml function of type fn : 'a -> 'b

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-10 18:19:32
问题 The function: fn : 'a -> 'b Now, are there any functions which can be defined and have this type? 回答1: There are two possible implementations for that function signature in Standard ML. One employs exceptions, the other recursion: val raises : 'a -> 'b = fn a => raise Fail "some error"; (* Infinite looping; satisfies the type signature, *) (* but won't ever produce anything. *) val rec loops : 'a -> 'b = fn a => loops a; The first solution may be useful for defining a helper function, say bug

SML function on record list

最后都变了- 提交于 2019-12-10 16:21:36
问题 I'm trying to declare a function that takes a list of records inside a tuple as an argument but the syntax is not as intuitive as I would have liked. Here's what I'm trying to do: type Player = {id:int, privateStack:int list}; fun foo(({id, x::xs}:Player)::players, ...) = (* wrong syntax *) (* do something *) 回答1: Pattern matching requires binding record fields to some values so you have to use explicit record syntax. Therefore, fun foo(({id = id, privateStack = x::xs})::players, ...) = (* do

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 ..