sml

Resolve library conflict in SML/NJ Compilation Manager

吃可爱长大的小学妹 提交于 2019-12-13 13:19:52
问题 I'm using SML/NJ 110.79, which includes support for new structures defined by the Successor ML project. Among others, the Fn structure. As it happens, I already had an identically named structure in one of my personal project with utilities, which worked fine before 110.79. With 110.79, for this .cm file: group is $/basis.cm $SMACKAGE/sml-extras/v0.1.0/sources.sml.cm I get the following error, though: sources.cm:3.3-3.45 Error: structure Fn imported from $SMLNJ-BASIS/(basis.cm):basis-common

SML functional programming higher order function?

与世无争的帅哥 提交于 2019-12-13 09:49:49
问题 I need to implement a function ziprev : 'a list -> 'b list -> ('a * 'b) list - ziprev [1,2,3,4] [10,20,30,40]; val it = [(1,40),(2,30),(3,20),(4,10)] : (int * int) list Using a function that I already created: - zipW (fn (x, y) => x + y) [1,2,3,4] [10,20,30,40]; val it = [11,22,33,44] : int list and the List.rev from the library. I have no idea how to do a function with two libraries. Any suggestions? 回答1: Hint 1: Compare the result of your ziprev with List.zip [1,2,3,4] [10,20,30,40] You

What is error of unresolved flex record in SML?

和自甴很熟 提交于 2019-12-13 04:19:17
问题 I am new to SML, and have asked people about the error that I got. But, I can't find where the problem is. The error message is received is: stdIn:10.1-16.48 Error: unresolved flex record (need to know the names of ALL the fields in this context) type: {1:''Y, 2:''X; ''Z} I have two functions. The first function is reverse, which is to reverse a list and return it. For example, reversing [1,2,3,4] to [4,3,2,1]. This function has absolutely no problems. fun reverse(L) = if L = nil then nil

Why do I use `let` and not just `val` to declare a variable inside a function in SML?

若如初见. 提交于 2019-12-13 03:53:56
问题 In SML, I've been taught the idiomatic way to define a variable local to the function as: fun correct_fun() = let val x = 1 in x + 2 end Why do I have to use let , and not just val like so: fun incorrect_fun() = val x = 1 x + 2 The incorrect_fun() throws an error but I don't understand why. Why can't val be used inside a function without let ? 回答1: Why can't val be used inside a function without let ? Because val is a kind of declaration, let is a kind of expression, and a function body is an

meaning of warning and type in ML

浪尽此生 提交于 2019-12-13 01:23:24
问题 fun a(list) = let val num = length(hd(list)) fun inner(list) = if num = length(hd(list)) then if tl(list) = nil then true else inner(tl(list)) else false in if length(hd(list))-1 = length(tl(list)) then inner(tl(list)) else false end; this is ml code and I got this warning and type. stdIn:6.16 Warning: calling polyEqual val a = fn : ''a list list -> bool I don't understand about the warning. why it appear and the type. ''a why it has two '? ''? what is the difference between 'a list list and

Seeding SML/NJ's RNG on a Windows machine

拈花ヽ惹草 提交于 2019-12-13 00:18:14
问题 How to seed SML/NJ's random number generator on a Windows machine? The function Random.rand() takes a pair of integers and uses them to seed the random number generator. Based on my experience with other porgramming languages, I would expect there to be a relatively easy way to seed it based on the system clock (something like srand(time(null)); in C). Unless I am overlooking something obvious, there doesn't seem to be any straightforward way, at least if you are using Windows. The closest I

ML function currying

情到浓时终转凉″ 提交于 2019-12-12 13:06:36
问题 Could someone please explain the concept of currying to me. I am primarily learning it because we are learning ML in my 'modern programming language' class for a functional language introduction. In particular you can use this example: -fun g a = fn b => a+b; val g = fn: int -> int -> int -g 2 3; val it = 5 : int I'm confused how these parameters are passed or how to even think about it in the first place. Thank you for any help. 回答1: In this case, you make the currying explicit, so it should

Can I annotate the complete type of a `fun` declaration?

ⅰ亾dé卋堺 提交于 2019-12-12 12:22:36
问题 In a learning environment, what are my options to provide type signatures for functions? Standard ML doesn't have top-level type signatures like Haskell. Here are the alternatives I have considered: Module signatures, which require either a separate signature file, or the type signature being defined in a separate block inside the same file as the module itself. This requires the use of modules, and in any production system that would be a sane choice. Modules may seem a little verbose in a

Syntax error in creating a list from a tree in SML

时间秒杀一切 提交于 2019-12-12 05:49:36
问题 I have the following two datatypes: datatype leaf = Slist of string list | Real of real | nil; datatype 'a tree = Empty | Node of leaf * 'a tree * 'a tree * 'a tree; The code below goes through all trees of length one/two and forms a list of the values in the leafs. fun list12(Empty:'a tree) = nil | list12(Node(leaf leaf1, 'a tree a1, 'a tree a2, 'a tree a3)) = if (not(a1 = Empty) andalso not(a2 = Empty) andalso not(a3 = Empty)) then list12(a1)::list12(a2)::list12(a3) else leaf1::list12(a1):

Call a Python file in a SML program?

一笑奈何 提交于 2019-12-12 05:26:33
问题 I was wondering if it is possible to call a python file in an SML program, and if so how can you do it? I have tried researching how to do this, but have only found documentation on how to call other SML files. 回答1: I think OS.Process.system "python myscript.py" should work. See: http://sml-family.org/Basis/os-process.html 来源: https://stackoverflow.com/questions/43353918/call-a-python-file-in-a-sml-program