I need to return a different value based on the function passed into another function.
So, given: fun inc x = x + 1;
And: fun double [] = [] | double (h::t) = 2*h::double (t);
You should be able to call the function I'm working on with either.
Example call (the function I'm making is named test):
test (inc, 5); - And it would return...
Is there any way to check/test the type of a variable?
I want to use it like this:
if x = int then foo
else if x = real then bar
else if x = string then ...
else .....
...
I'm having a bit difficulty figuring out, how to get each of the processed chars back to an int value.
The function should work like: val caesar = fn : int * int -> int
So if k = 2466 and n = 2, then the output should be 4688
Hope the code isn't too weird (I'm a SML newbie).
(* Load Libs *)
load "Int";
load "Real";
loa...
I'm trying to subtract 2 lists and return the compared product.
So if list
a = [2,3,2]
b = [1,1,1]
then
a-b = [1,2,1] and the returned product (c) should be 1.
val c = List.map (fn i => (i - b) mod 10) a
modulo (mod) 10 is for cases where the two subtracted numbers gives an odd result, e.g. 2-8 = ~6 mod 10 = 4.
I'm stuck at th...
Hi
I have a program that returns int*int
(Example for illustration purposes):
fun program(a,b) = (1,2)
I want to do something along the lines:
fun program(a,b)
if a = 0 then (1,2)
else
val x,y = program(a-1,b)
return (x-1, y)
Basically, I want to manipulate the tuple that is returned, and then return a modific...
I just started university and managed to spend my entire first week sick, so I'm having a hard time figuring this out. I'm supposed to crack the caesar cypher.
I have to declare a function crack : int * int -> int so that if (k, c) are of the type int, where k is the decrypted text and c the encrypted text, calling crack(k, c) will retu...
I'm new to SML, and I was wondering how to get an element in a list of tuples. For example, in the list [("abc", 4), ("def", 6)], how could you extract "abc"? I've tried
x::xs => #1(x)
but I keep getting "unresolved flex record". Any suggestions?
...
I have an assignment where I have to implement church numerals in sml using the datatype: datatype 'a church = C of ('a -'a) * 'a -> 'a
I have to write the function create :int -> 'a church and a function churchToint so far I have the following code:
datatype 'a church = C of ('a -> 'a) * 'a -> 'a
val ZERO = C(fn (f,x) => x)
fun subCrea...
Hey, im very new to SML and programming alltogether, i want to write a function that combine within lists, such that
[x1,x2,x3,x4,...] = [(x1,x2),(x3,x4),...] Any hints or help for me to go in the right direction is highly appreciated.
...
I'm practicing with sml and I'm doing a small assignment where we have to implement church numerals defined as:
datatype 'a church = C of ('a -> 'a) * 'a -> 'a
example val
ZERO = C(fn (f,x) => x)
I have already implemented the functions:
create: int -> 'a church
churchToInt: 'a church -> int
and SUC which returns the su...
Hi there, i want to write a function that checks for equality of lists in SML
for instance :
[1,2,3]=[1,2,3];
val it = true : bool
So instead of writing down the whole thing, i want to make a function that takes two predefined lists, and compare them, so that if list01 = [1,2,3] and list09 = [1,2,3]
then fun equal (list01,list09); will ...
Hey, i want to program a function delete that given a tree, i can delete a node in the tree so it should return the original tree minus the node and the subtree of this node.
every hint helps, and thanx in advance:)
...
Two people considered identical if they have exactly the same information (same name, sex, birth and death).
I must declare a function pers: person * person -> bool that determines whether two values of type person enter the same person.
I'm stucked, anyone ? tnx.
...
Hello,
I have an sml assignment and one of the questions is to implement a function:
findAll (int -> bool) -> binary search tree -> int list
I have the following so far:
datatype 'a tree = Empty | Node of (int * 'a tree * 'a tree)
exception answer of int list
fun findAll f Empty = raise answer []
| findAll f (Node(x, l, r)) = ...
I have an assignment, and I can't figure out what to do about it. I have a tree of people with their name, birth and death year. Think genealogy here. I have a bunch of datatypes to take care of ages, names, the tree itself, etc. and then I have a bunch of people and a tree.
The datatypes are:
datatype year = Year of int | UnkYear |...
I was advised to ask this as a separate question, so that I will do.
I have a tree of people, like in genealogy. It starts with a person and branches off into parents, grandparents, etc. I want to be able to insert a person into a spot on the tree (basically replacing whoever is there).
These datatypes are important:
datatype year ...
How to declare a function suffixsen : string list -> string list ???
Tnx.
...
Hey, im trying to declare a function, string list -> string, that with the input for instance
["Chicago","city","USA"] should return "Chigago city USA". And im having a bit of trouble,
what i did so far was this:
fun gather ts = foldr op ^ "" ts;
This seems to be somewhat along the lines, however the problem is, i would like to includ...
I have given : spacegather : string list -> string
I have to make a function, so it turns the call:
spacegather ["I", "am", "nice"] to -> "I am nice"
thanx
...
Declare a function of
shortLong: string list -> int * int
, so the result of a call
short long ts becomes (k, l) where k is the number of texts in ts with six or fewer characters, and l is the number of texts in ts with seven or peripheral characters. Try to express the short-long in such a way that the argument "not" be run two, but...