Questions tagged [sml]

Standard ML is a high-level functional language with type inference.

sml
Filter by
Sorted by
Tagged with
1 vote
1 answer
842 views

Standard ML: BubbleSort with Arrays

I'm trying to implement bubblesort using arrays but am having a tough time doing so. Here's what I have so far: fun swap(A, i, v) = let val temp = sub(A, i); in update(A, i,...
anon_swe's user avatar
  • 9,071
0 votes
1 answer
200 views

Truncation in ML Part 2

I'm nearly there on truncating a string in ML, but am getting an error about not handling an empty list. Here's my code and the error: fun getAllButLast([x]) = nil | getAllButLast(x::xs) = x::...
anon_swe's user avatar
  • 9,071
1 vote
1 answer
726 views

Standard ML: Lookup Function in Binary Search Tree

I'm making my way through Ullman's Elements of ML Programming. He introduces a datatype for a BST in ch. 6 as follows: datatype 'label btree = Empty | Node of 'label * 'label btree * 'label ...
anon_swe's user avatar
  • 9,071
0 votes
1 answer
141 views

Standard ML static errors

I have to write a function that computes this datatype : datatype Expr = X | Y | Avg of Expr * Expr | Mul of Expr * Expr; and I cannot find the error in the following funtion; val rec compute => ...
WisdomPill's user avatar
1 vote
1 answer
215 views

Standard ML: Truncating String

I know ML has a bunch of string methods (substring, etc) that would make this easier but I want to get more comfortable with the language, so I'm implementing some myself. I'm trying to truncate a ...
anon_swe's user avatar
  • 9,071
0 votes
1 answer
866 views

Standard ML: Basic Conversion to Uppercase Character

I'm trying to write a function that converts a lower case character to uppercase (if uppercase, leave unchanged). Here's what I've written: fun toUpper(myChar) = exception invalidCharacter; ...
anon_swe's user avatar
  • 9,071
2 votes
1 answer
176 views

F# - Mono crashes/ returns inconsistent

I am trying to learn F# and I have some background in Standard ML. I am working through the text "Functional Approach to Programming" converting its code into F#. The code sample presented below is ...
FooBarLearnsToCode's user avatar
2 votes
3 answers
127 views

Standard ML: Ugly isLeapYear Function

I'm trying to write a function in Standard ML using case of but I end up with code that screams for a bunch of if / else's. Is this just a poor candidate for using case of or is there a better way of ...
anon_swe's user avatar
  • 9,071
1 vote
1 answer
2k views

Standard ML: Operator and Operand Don't Agree (Circularity)

I'm trying to write a function in SML to flip alternate elements of a list. Here's my function: fun flipAlternate(nil) = nil | flipAlternate([x]) = x | flipAlternate(x::y::xs) = y::x::...
anon_swe's user avatar
  • 9,071
1 vote
1 answer
1k views

Few questions about sml zip function

I am new to sml, now I am trying to define a zip function which takes two lists as a tuple. here are the code. I got it working, but I have a few questions exception Mismatch; fun zip ([],[]) = [] ...
hao's user avatar
  • 23
2 votes
1 answer
238 views

Standard ML: Backtracking Confusion

I'm confused by an example Harper gives in his Intro to SML on p. 110. He's writing a function to make a certain amount of change from a list of coin values, backtracking when needed. e.g. If I run ...
anon_swe's user avatar
  • 9,071
6 votes
2 answers
288 views

Standard ML: Confusion about Reference Cells

I'm reading Harper's Intro to SML and am a bit confused on reference cells. On p. 114, he gives the following example: val r = ref 0 val s = ref 0 val _ = r := 3 val x = !s + !r val t = r val _ = t :...
anon_swe's user avatar
  • 9,071
0 votes
1 answer
60 views

SML: What does this this function guess : bool * ('a * 'a) -> 'a * 'a calculate?

From an old exam I had this SML function and I should give an answer on what this function calculates. fun guess(e,(a,b)) = if e then (a,b) else (b,a) The signature is bool * ('a * 'a) -> 'a * 'a ...
Christoph S's user avatar
0 votes
2 answers
99 views

Standard ML: Unsure of Type of Higher Order Function

I'm reading Harper's book, Intro to Standard ML, and am a bit confused on section 11.3, Returning Functions. 1) He defines a function that creates constant functions. He writes: "Given a value k, ...
anon_swe's user avatar
  • 9,071
3 votes
1 answer
305 views

Standard ML comment formatting is faulty in vim

I have tried the following commands for formatting comments in ~/.vim/after/indent/sml.vim set comments=s1:(*,mb:*,ex:*) set comments=sr:(*,mb:*,ex:*) set comments=s1:(*,mb:\ *,ex:*) set comments=sr:(...
neoDaedalus's user avatar
4 votes
2 answers
2k views

Standard ML: Datatype vs. Structure

I'm reading through Paulson's ML For the Working Programmer and am a bit confused about the distinction between datatypes and structures. On p. 142, he defines a type for binary trees as follows: ...
anon_swe's user avatar
  • 9,071
2 votes
1 answer
386 views

What are some high quality Standard ML code/projects to learn from? [closed]

I'm trying to learn to write elegant Standard ML code by reading others' code or projects. Does anyone know of some good code/projects?
Ben's user avatar
  • 3,822
2 votes
1 answer
941 views

SML - Find element in a list and substitute it

I'm trying to build a function which takes as input two list of type (string*string) list and returns one list of the same type. The first list is like a "lookup" list in which the second element ...
gabribass89's user avatar
1 vote
1 answer
979 views

Wildcards in Standard ML

I just came across the following function in ML for the Working Programmer: fun null [] = true | null (_::_) = false 1) Can't both wildcards be empty lists? If not, how does ML prevent this? 2)...
anon_swe's user avatar
  • 9,071
3 votes
1 answer
1k views

Standard ML: Iterative vs. Recursive

I'm reading through ML for the Working Programmer and am a bit confused by the author's distinction between iterative and recursive. My understanding was that "recursive" just refers to a function ...
anon_swe's user avatar
  • 9,071
0 votes
3 answers
2k views

Functors with multiple inputs in Standard ML

High level question: How do I use functors with multiple arguments in SML? I've looked at this, this, this and this(PDF). All of them seem to conflict in terms of structure or functor definition ...
Inaimathi's user avatar
  • 13.9k
1 vote
2 answers
1k views

Standard ML: Getting Last in List

I'm trying to get the last element of a list of integers in SML but I want to indicate (somehow) when the user passes in an unacceptable list (such as an empty one). My code is here: fun lastInList [...
anon_swe's user avatar
  • 9,071
1 vote
1 answer
134 views

mlton gives library-related error

When I try to compile a program with mlton, I get an error. ~/projects/serve-sml $ mlton server.mlb In file included from /usr/lib/mlton/include/platform.h:13:0, from /usr/lib/mlton/...
Inaimathi's user avatar
  • 13.9k
1 vote
1 answer
399 views

Standard ML / NJ: Loading in file of functions

I'm trying to write a bunch of functions in an SML file and then load them into the interpreter. I've been googling and came across this: http://www.smlnj.org/doc/interact.html Which has this ...
anon_swe's user avatar
  • 9,071
0 votes
1 answer
149 views

ML currying and anonymous functions

Could someone please explain to me what is going on in these three bindings? What is the significance of the parens? What is the meaning of g and why does it have to be a g as an argument in the ...
doubleOK's user avatar
  • 353
-2 votes
1 answer
562 views

SML - Unzip tuples in one list

I need to "unzip" a list of tuples and even though I tried with the unzip function it doesn't do what I want to. In fact, as I understood the unzip function returns you a tuple of list, but what i ...
gabribass89's user avatar
3 votes
2 answers
151 views

How to discover (possibly approximate) dependencies between SML source files?

I have software written in Standard ML (henceforth SML) which I'd like to make portable across three compilers. Standard ML of New Jersey is the easiest, as their Compilation Manager does the ...
Norman Ramsey's user avatar
2 votes
1 answer
75 views

What `type variables` means when they occurred in `val` declaration statement in SML

In SML/NJ repl, the following expression is accepted: - val 'a a = []; val a = [] : 'a list - val 'a a = 1; val a = 1 : int What's the 'a means here? I don't know what effect will they made, and ...
AuBee's user avatar
  • 86
0 votes
1 answer
294 views

SML - Find same elements in a string

Sorry but I need your help again! I need a function which takes as input a list of (string*string) and returns as output a list of (int*int) The function should manipulate the list such that, ...
gabribass89's user avatar
3 votes
1 answer
268 views

Handling Keyboard Interrupts

I've got a minimal TCP server running in the SML/NJREPL, and I'm wondering how to gracefully close the listener socket on a keyboard interrupt. A stripped-down version of the server is fun sendHello ...
Inaimathi's user avatar
  • 13.9k
3 votes
1 answer
290 views

Large Int Set in sml

I'm having the following problem in sml: i want to create a set using the IntListSet signature but instead of int I want to use large int. Is there any way to fix this? Thank you, awaiting for your ...
ysig's user avatar
  • 477
2 votes
1 answer
88 views

Type error calling select Standard ML

I'm trying to call Socket.select to deal with some sockets. It seems like the following minimal snippet from my code should work... fun descs ss = map Socket.sockDesc ss fun selecting server clients ...
Inaimathi's user avatar
  • 13.9k
1 vote
1 answer
98 views

How to use Socket.select

How do I go about using Socket.select in Standard ML? According to the docs, I'm supposed to pass it three lists of sockets and a timeout option, and the function returns when any of the sockets are ...
Inaimathi's user avatar
  • 13.9k
2 votes
1 answer
382 views

Using TCP in Standard ML

I'm trying to write a minimal TCP server in Standard ML and getting some type errors I don't understand. What I've got so far is fun sendHello sock = let val res = "HTTP/1.1 200 OK\r\nContent-...
Inaimathi's user avatar
  • 13.9k
3 votes
4 answers
6k views

Zip and unzip lists in Standard ML

How to create a function to zip and unzip two lists as tupled lists in Standard ML? Example: unzip [[1,4],[2,5],[3,6]] -> [1,2,3] [4,5,6] zip [1,2,3] [0,2,4] -> [[1,0],[2,2],[3,4]]
jetpackman's user avatar
-1 votes
1 answer
734 views

SML - Recursive function for list string

I need your help! I'm trying to create a function that takes as input two elements of type (string*string*string) list and (string*string) list and return an element of type (...
gabribass89's user avatar
0 votes
1 answer
428 views

Trouble Installing Standard ML

So I'm trying to install Standard ML/NJ on a Mac running Yosemite. I download the installer for Mac OS X PPC and try to install. I get an error saying "The installation failed. The installer ...
anon_swe's user avatar
  • 9,071
2 votes
1 answer
235 views

ML abstract data type

I am trying to use abstract data types in Standard ML. For example, I could write a signature Queue, and two queues implementations by defining two structures as queues: signature Queue = ... ...
zg12's user avatar
  • 23
2 votes
1 answer
189 views

Operator and operand don't agree can't find why

I'm working on this code and can't make it run. I've checked it few times and still can't figure out why it's not working. fun date_to_string (date : (int * int * int)) = let val months = ["...
SuperManEver's user avatar
  • 2,312
26 votes
4 answers
7k views

Functional Breadth First Search

Functional depth first search is lovely in directed acyclic graphs. In graphs with cycles however, how do we avoid infinite recursion? In a procedural language I would mark nodes as I hit them, but ...
N. McA.'s user avatar
  • 4,896
-1 votes
1 answer
196 views

How to change the datatype of an existing tree in SML?

I need to solve this problem. I really have no clue. Any help would be greatly appreciated. I guess a traversal needs to be done but I have no idea how to attack this problem. Thanks in advance. ...
randomAsker's user avatar
0 votes
1 answer
1k views

How turn list of pair in list of int, where result int is sum of pair

I try to define function with the following protocol: [(1,2), (6,5), (9,10)] -> [3, 11, 19] Here is what I have now: fun sum_pairs (l : (int * int) list) = if null l then [] else (#1 hd(l)) ...
SuperManEver's user avatar
  • 2,312
2 votes
1 answer
545 views

Structuring a Library in SML

I'm currently building a testing library in Standard ML (using Poly/ML as the interpreter). I have the following directory structure: project/a.sml project/src/b.sml project/src/c.sml ... Where a....
Alex Coplan's user avatar
  • 13.3k
1 vote
1 answer
4k views

Overload conflict in ML (SML/NJ)

I have written the following piece of code for ML: fun get_digits (0, s) = s | get_digits (d, s) = get_digits( d div 10, (d mod 10) :: s) | get_digits n = get_digits( n div 10, [n mod ...
Angelos's user avatar
  • 11
0 votes
1 answer
79 views

isSubstring method in ML

fun appear(x:string,y:string)= if String.isSubstring x y then print("APPEAR ") else print("NOT APPEAR "); appear("abc","asabcbc"); I wrote this function and compiled in Moskow ML.But there is an ...
batuhan's user avatar
1 vote
2 answers
255 views

Read a single character or byte from stdIn without waiting for newline in SML

I encountered a problem while working with the TextIO structure, because every input waites for a newline chacter and for the buffer to be full... How can i work with BinIO and stdIn to solve that ...
Flux's user avatar
  • 11
0 votes
1 answer
67 views

Apply a list of parameters to a curried function

simple task: all I want is a function to apply a list of parameters to a curried function. Let's say our function is the famous add one: fun add a b = a + b; Now all I want is a function to apply a ...
scheffield's user avatar
  • 6,687
11 votes
1 answer
1k views

Printing only print output with SML/NJ

I'm trying to use SML/NJ, and I use sml < source.sml to run the code, but it prints out too much information. For example, this is the source.sml: fun fac 0 = 1 | fac n = n * fac (n - 1) val r ...
prosseek's user avatar
  • 187k
0 votes
1 answer
281 views

sml-mode in Emacs for Mac

I just created a .sml file but as I started to write, I realized that Emacs for Mac OS X didn't recognize the language. I would love to have colored text and auto-indentation if possible! I looked at ...
Jed's user avatar
  • 504
4 votes
2 answers
2k views

Convert Array to List in SML

How do i convert an array type to a list type in sml. I have searched the list and array structure functions but have not found one that does this (there is a list to array function though). ...
abden003's user avatar
  • 1,325

1
21 22
23
24 25
42