r/sml • • Oct 17 '20

How to create a list containing all the permutations of a list using only recursion?

0 Upvotes

Trying to figure out how to get a function that takes a list and returns a list of lists such that the function returns a list of all the permutations of the input list using only recursion and I can't use map or currying.

Example: perms([0,1,2])= [[0, 1, 2], [0, 2, 1], [1, 0, 2], [1, 2, 0], [2, 0, 1], [2, 1, 0]].

Any help would be appreciated.


r/sml • • Oct 09 '19

How do I write a function that takes in 2 lists and returns true if the 2 lists have at least 1 common element?

0 Upvotes

Here is what I have so far.

fun contains(x, []) = false |contains(x,y::rest) = if x = y then true else contains(x, rest);

fun hce([][]) = false |hce(x::xs,y) = if contains(x,y) then true else false;


r/sml • • Oct 05 '19

Write a function containsOne that, given a list of ints, determines whether that list contains 1.

0 Upvotes

What I have so far returns true false true etc for each 1 and non 1 as a list. I need to return only true or only false.

fun isOne(n) =n = 1;

fun containsOne([]) = [] | containsOne(x::rest)=isOne(x)::containsOne(rest);


r/sml • • May 05 '09

Totally AWESOME editor for your SML projects

Thumbnail
gnu.org
3 Upvotes

r/sml • • Jun 22 '26

I'm building out a vast ecosystem (200+ repositories so far)

8 Upvotes

Hi all,

I always thought SML looked better than OCaml, and the only reason not to use it was that there were no libraries. But if I make some libraries, maybe it'll catch up. Idk.

I built out a bunch of useful shit here

https://github.com/sjqtentacles?tab=repositories&q=&type=source&language=standard+ml&sort=

over 200 repositories so far! Still working on more.


r/sml • • Oct 09 '19

Write a function removeFirst that takes an item and a list and returns a list like the given one except that the first occurrence, if any, of the given item is removed. For example, removeFirst(5, [1,2,6,5,2,4,59]) would return [1,2,6,2,4,59].

0 Upvotes

Here is what I have so far:

fun contains(x, []) = false |contains(x,y::rest) = if x = y then true else contains(x, rest);

fun removeFirst(y, []) = [] |removeFirst(y,x::rest) = if contains(y, x::rest) then removeFirst(y,rest) else x::removeFirst(y,rest);


r/sml • • Oct 10 '19

Need some doubts which need to clarified related to parsing.

0 Upvotes

Hit me up if you're willing to help


r/sml • • Jan 31 '17

How to solve this problem using recursion only?

Post image
0 Upvotes

r/sml • • Oct 05 '19

Using contains, write a function intersection which takes two lists(modeling sets) and returns a list modeling the intersection of those two sets.

0 Upvotes

fun contains(x, []) = false |contains(x,y::rest)=if x=y then true else contains(x, rest);

take in 2 lists. return a list of what they have in common.


r/sml • • Jan 21 '15

[Need help] Cannot install sml/nj on 64bit Fedora

1 Upvotes

I followed the instructions on the sml/nj site http://smlnj.org/install/index.html but I run into the issue that it asks me to install the 32bit library which I also tried to install libgcc-multilib from rpmseek. The problem is that my system is slinging me a conflict with another package. Here's what I get:

warning: libgcc-multilib-4.7.1-8.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID e4f1bc2d: NOKEY
file /lib/libgcc_s.so.1 from install of libgcc-multilib-6:4.7.1-8.x86_64 conflicts with file from package libgcc-4.9.2-1.fc21.i686

Thank you for the help in advance


r/sml • • May 03 '11

QCheck: a library for automatic unit testing in the spirit of Haskell QuickCheck.

Thumbnail
contrapunctus.net
2 Upvotes

r/sml • • Feb 25 '17

Explain the meaning if (int -> int)?

2 Upvotes

I'm doing a homework assignment where this pops up:

type 'a cont  = 'a SMLofNJ.Cont.cont
type choice   = int cont * (int -> int) * int

and I'm confused as to what (int -> int) means. I've seen it before in programs but never in the equation of one. Any explanation would be really appreciated. Also, I'm assuming the 'a cont is an import. If you have any idea what is being imported I'd like to know. Thanks.


r/sml • • May 05 '09

Another really AWESOME SML interpreter and compiler.

Thumbnail itu.dk
2 Upvotes

r/sml • • May 05 '09

BREAKING: Great SML compiler

Thumbnail
smlnj.org
2 Upvotes

r/sml • • Nov 03 '13

sml vs haskell performance

2 Upvotes

Hi guys, did anyone compare sml (smlnj, mlton) performance vs haskell (ghc) ?


r/sml • • Oct 15 '25

New SML learner - can't figure out how SML chooses which datatype can be passed into a function.

10 Upvotes
fun length x =
    if null x then 0
    else 1 + length(tl x);

fun thirdElem L = 
    if length(L) < 3 then 0
    else hd(tl(tl(L)));

I understand that a function takes a value of a certain datatype, and returns a value of a certain datatype, but it gets annoying when I want a function fn: 'a list -> int but the function I coded becomes int list -> int.
For example, the function thirdElem is fn: int list -> int, which means it absolutely cannot work on anything but an int list, like a char list or string list, even though I want it to.

So in order to have it accept more than just an int list, I would need to turn it into fn: 'a list -> something else.
Is there absolutely no way to do this? Because the length example from my book takes 'a list so it will work on an int list, char list, whatever.


r/sml • • Jun 22 '25

matrix.org #StandardML room (re-post)

3 Upvotes

It took some time for me to find this (original announcement):

https://www.reddit.com/r/sml/comments/kacoad/join_the_standard_ml_chat_at_standardmlmatrixorg/

Room is here: https://app.element.io/#/room/#standardml:matrix.org

Its slightly better experience than #sml on libera IRC.


r/sml • • Apr 20 '14

CUFP 2014: Call For Presentations

Thumbnail
cufp.org
3 Upvotes

r/sml • • May 18 '10

No _THIS_ is what a real SML programmer looks like.

Thumbnail
cl.cam.ac.uk
4 Upvotes

r/sml • • Oct 24 '14

Was the "Modular Type Classes" translation ever implemented?

4 Upvotes

Dreyer, Harper, Chakravarty, and Keller's POPL'07 paper describes a very elegant system for type classes (and therefore overloading) on top of Standard ML. It is defined as an elaboration: it takes a program in SML+Classes and outputs a program in ordinary SML.

Was this translation ever implemented anywhere?

Ideally I'm hoping for a standalone translation, but I might switch SML compilers if the only implementation is compiler-specific.


r/sml • • Apr 06 '12

Smackage, package manager for Standard ML libraries

Thumbnail
github.com
4 Upvotes

r/sml • • Jul 20 '13

SML#: a new Standard ML family programming language

Thumbnail pllab.riec.tohoku.ac.jp
5 Upvotes

r/sml • • Jun 09 '19

IDE for SML

5 Upvotes

I know there is SML mode for Emacs but since I use Vim, I do not really want to use Emacs.. also I do not want to go into configuring Emacs just for writing SML.

There is a plugin for Vim `vim-better-sml` but I do not particularly like it.. there is no linter and the auto-indentation also feels clunky. It also only supports an embedded REPL with Vimux or Neovim, neither of which I use.

I feel most comfortable with VS Code or Jetbrains IDEs...

Are there any IDEs you could recommend for SML?


r/sml • • Nov 17 '14

Experimental library for bulk memory operations with Standard ML in MLton.

Thumbnail
github.com
5 Upvotes

r/sml • • Sep 08 '22

What data structure is used instead of associative arrays or hash tables (in SML in particular or FP in general)?

5 Upvotes

I'm trying to implement some algorithms with memoization. Some can be done with arrays, but some need the keys to be strings or integers without regular patterns.

How is this done in SML? SML/NJ has a hash table implementation, but is implementing the associative array ourselves the only pure SML option?

Take leetcode problem 1 as example. The optimization uses an associative array (python's dictionary in this example).

def two_sum(nums: List[int], target: int) -> List[int]:
        hashmap = {}
        for i in range(len(nums)):
            complement = target - nums[i]
            if complement in hashmap:
                return [i, hashmap[complement]]
            hashmap[nums[i]] = i

How can something like this be achieved with pure SML? Should this optimization be approached in another way?