sml

How to read string from user keyboard in SML language?

£可爱£侵袭症+ 提交于 2020-06-29 04:23:50
问题 I am new to the SML language and I want to do this: to ask a person "what is your full name?" to get answer from user's keyboard and to write "your full name is"+name (his or her name that answered) 回答1: This answer has three parts. The first part answers your only question. The second part answers a question you seem to be fishing for without asking it, and the third part addresses how to find answers to questions by your own means. How to read string from user keyboard in SML language? You

C : Sum of reverse numbers

半世苍凉 提交于 2020-06-25 03:22:10
问题 So I want to solve an exercise in C or in SML but I just can't come up with an algorithm that does so. Firstly I will write the exercise and then the problems I'm having with it so you can help me a bit. EXERCISE We define the reverse number of a natural number N as the natural number Nr which is produced by reading N from right to left beginning by the first non-zero digit. For example if N = 4236 then Nr = 6324 and if N = 5400 then Nr = 45. So given any natural number G (1≤G≤10^100000)

Usage of the ref function in ML

不打扰是莪最后的温柔 提交于 2020-05-29 06:46:11
问题 Considering the ref operator I'm having trouble to understand its application and the sense of the follow instructions: 1. In this definition what am I defining? - val ref x=ref 9; val x = 9 : int 2. and here what am I doing with ref x:= ref 12? - val x= ref 8; val x = ref 8 : int ref - ref x := ref 12; val it = () : unit - x; val it = ref 8 : int ref 回答1: val ref x = ref 9 defines x to be 9 - just as if you had written val x = 9 . This is because ref is a constructor, so it's pattern

number_in_month exercise (SML error unbound variable)

这一生的挚爱 提交于 2020-04-20 05:24:51
问题 I am trying to learn SML, and I am trying to implement two functions. The first function works fine, but when I added the second function it gives me an run-time error: stdIn:1.2-1.17 Error: unbound variable or constructor: number_in_month This happens while calling the function number_in_month. My code is: fun is_older(d1 :int*int*int,d2 :int*int*int) = (#1 d1) < (#1 d2) andalso (#2 d1) < (#2 d2) andalso (#3 d1) < (#3 d2) fun number_in_month(da :(int * int * int) list ,mo : int) = if da = []

number_in_month exercise (SML error unbound variable)

放肆的年华 提交于 2020-04-20 05:20:47
问题 I am trying to learn SML, and I am trying to implement two functions. The first function works fine, but when I added the second function it gives me an run-time error: stdIn:1.2-1.17 Error: unbound variable or constructor: number_in_month This happens while calling the function number_in_month. My code is: fun is_older(d1 :int*int*int,d2 :int*int*int) = (#1 d1) < (#1 d2) andalso (#2 d1) < (#2 d2) andalso (#3 d1) < (#3 d2) fun number_in_month(da :(int * int * int) list ,mo : int) = if da = []

number_in_month exercise (SML error unbound variable)

泄露秘密 提交于 2020-04-20 05:18:55
问题 I am trying to learn SML, and I am trying to implement two functions. The first function works fine, but when I added the second function it gives me an run-time error: stdIn:1.2-1.17 Error: unbound variable or constructor: number_in_month This happens while calling the function number_in_month. My code is: fun is_older(d1 :int*int*int,d2 :int*int*int) = (#1 d1) < (#1 d2) andalso (#2 d1) < (#2 d2) andalso (#3 d1) < (#3 d2) fun number_in_month(da :(int * int * int) list ,mo : int) = if da = []

Curried Functions in Standard ML

我只是一个虾纸丫 提交于 2020-04-13 08:02:49
问题 I've been banging my head against the wall trying to learn about curried functions. Here's what I understand so far; suppose I have a function: fun curry (a b c) = a * b * c; or fun curry a b c = a * b * c; In ML, I can only have one argument so the first function uses a 3-tuple to get around this / get access to a , b , and c . In the second example, what I really have is: fun ((curry a) b) c where curry a returns a function, and (curry a) b returns a function and ((curry a) b) c returns

what does “syntax error found at EOF” means and why am i getting it for this recursive function?

浪子不回头ぞ 提交于 2020-03-23 14:43:05
问题 I'm getting the error in SMLNJ: Error: syntax error found at EOF what does this means? The function that seems to be causing the error is the following. fun number_in_month (dates : int*int*int list, month : int) = if null dates then 0 else if #2 (hd dates) = month then number_in_month(tl dates, month) + 1 It is supposed to take a list of dates ( int*int*int list) and a month ( int ) and returns how many dates in the list are in the given month. Thanks for your kind help. 来源: https:/