diff options
| author | Shinya Sato <shinnya.sato@gmail.com> | 2022-05-02 09:49:01 +0900 |
|---|---|---|
| committer | Shinya Sato <shinnya.sato@gmail.com> | 2022-05-02 09:49:01 +0900 |
| commit | 8c7809d024e85d0a8acfb794a4db41b0e4bc13e6 (patch) | |
| tree | 25ac81bad7be415d7cf75457275f7161d79f9f10 /comparison/SML/dummy.sml | |
| parent | 429543c748aaf81b2a4207318eb5a05259469b21 (diff) | |
| download | inpla-8c7809d024e85d0a8acfb794a4db41b0e4bc13e6.tar.gz inpla-8c7809d024e85d0a8acfb794a4db41b0e4bc13e6.zip | |
v0.8.2-1
Diffstat (limited to '')
| -rw-r--r-- | comparison/SML/dummy.sml | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/comparison/SML/dummy.sml b/comparison/SML/dummy.sml new file mode 100644 index 0000000..15ff263 --- /dev/null +++ b/comparison/SML/dummy.sml @@ -0,0 +1,55 @@ +(* https://stackoverflow.com/questions/25839939/understanding-merge-sort-in-ml *) + +fun split [] = ([], []) + | split [a] = ([a], []) + | split (a::b::cs) = + let + val (m,n) = split cs + in + (a::m, b::n) + end; + +fun merge ([], ys) = ys + | merge (xs, []) = xs + | merge (x::xs, y::ys) = + if x<y then + x::merge(xs, y::ys) + else + y::merge(x::xs, ys); + +fun msort [] = [] + | msort [a] = [a] + | msort [a,b] = if a<b then [a,b] else [b,a] + | msort xs = + let + val (m,n) = split xs; + in + merge (msort m, msort n) + end; + + +(* Creates a random list *) +local + val nextInt = Random.randRange(1,10000); + val r = Random.rand(1,1); +in + fun mkRandList 0 = [] + | mkRandList n = (nextInt r)::(mkRandList (n-1)) +end; + + +(* Validation checks *) +fun validation [] = true + | validation (x::xs) = + let fun validation_cons x [] = true + | validation_cons x (y::ys) = + if x<=y then validation_cons y ys + else false + in + validation_cons x xs + end; + + +(* Main *) +validation(msort (mkRandList 10)); + |
