smlnj

Standard ML multiple condition statement

喜夏-厌秋 提交于 2019-12-14 03:21:51
问题 I am about finished with a script I am writing but I have one last condition statement to add to my function. fun whileloop (x:real,a:int,b:real) = if (a<1) then (x,a,b) else whileloop(x+1.0,a-1,b-1.0) This is my current loop I have created. It is basically accomplishing everything I need under one exception. I want it to exit its loop once the b variable hits zero[if this happens before a reaches zero). I believe Standard ML will not let me do a condition statement for a real variable...such

How to generate an infinite list of fibonacci numbers using curried function in SMLNJ?

余生长醉 提交于 2019-12-13 18:50:28
问题 I have coded up a general purpose routine that takes multiple arguments and generates an infinite list of fibonacci numbers which is as follows: datatype 'a seq = Nil | Cons of 'a * (unit -> 'a seq) ; fun fibo (a,b) = Cons(a, fn () => fibo(b,a+b)); val fib = fibo(0 , 1); But the problem is I want to use currying technique to generate this infinite list of fibonacci numbers starting from 0 and 1, I am totally perplexed about the concept of currying. Can some enlighten me about the concept of

SML tuples - Combination

三世轮回 提交于 2019-12-13 17:58:09
问题 I've come across a tuples problem where given a list of pair tuples it should become a pair of lists: i.e. [(1,2),(3,4),(5,6)] should return ([1,3,5],[2,4,6]) . I've tried to solve it using this code: fun convert L = foldl (fn(a,b) => #1a::b) [] L; But I get an error saying: unresolved flex record. Anyone able to explain why I'm getting this and how it could be fixed? 回答1: Looking at a , the compiler can tell it's supposed to be a tuple (since you're calling #1a ), but it can't tell how big

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

foldl definition possible wrong in SML/NJ 110.75

99封情书 提交于 2019-12-13 06:23:13
问题 The signature of foldl in SML/NJ 110.75 is foldl; val it = fn : ('a * 'b -> 'b) -> 'b -> 'a list -> 'b Also if I give: foldl (op -) 2 [1]; I will take as answer ~1 instead of 1 Can you confirm my findings? 回答1: From the basis library: http://www.standardml.org/Basis/list.html#SIG:LIST.foldl:VAL foldl f init [x1, x2, ..., xn] returns f(xn,...,f(x2, f(x1, init))...) or init if the list is empty. thus in foldl (op -) 2 [1] the result is the evaluation of xn - init or 1 - 2 What makes this

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

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

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

Write command-line arguments to file in SML

独自空忆成欢 提交于 2019-12-12 04:12:22
问题 I am trying to write the command line arguments from my SML program into a file, each on a separate line. If I were to run sml main.sml a b c easy as 1 2 3 on the command line, the desired output would be to have a file with the contents: a b c easy as 1 2 3 However, I am getting the following output from SML : $ sml main.sml a b c easy as 1 2 3 val filePath = "/Users/Josue/Desktop/espi9890.txt" : string val args = ["a","b","c","easy","as","1","2","3"] : string list main.sml:4.21 Error: