kig / preludeml

OCaml stdlib replacement with a Haskellish flavour

This URL has Read+Write access

Ilmari Heikkinen (author)
Mon Feb 16 15:01:15 -0800 2009
commit  f2203f4f461af89ba7fee25f90e93f04ad8440d4
tree    2a0c53f671ab5e871452137f194dca7f84f165da
parent  85aa9166718aecfd9fafaa5839ebe00e71abc82f
preludeml / README
100644 104 lines (72 sloc) 3.2 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
Prelude.ml: an OCaml stdlib replacement with a Haskellish flavour.
 
 
Requirements:
  pcre, netstring (ocaml-net)
  oUnit for the tests
 
Compile:
  omake
 
Run tests:
  omake test
 
Run tests, printing out the test name before running it:
  omake test_verbose
 
Released under the MIT license.
 
 
Features
--------
A more consistent interface across lists, arrays, strings and bytestrings.
Bytestrings, strings wrapped in char_of_int / int_of_char.
Parallel combinators for (1D) Bigarrays and the aforementioned collections.
Shell command utilities.
Filesystem utilities.
Path utilities.
IO utilities.
User/group utilities.
Time utilities.
Function combinators, option combinators, exception combinators,
tuple combinators, comparisons, conversions, recursions, floats, ints,
hashes, maps, unfolds, folds, scans, spans, slices and subs.
 
Everything in a single module for a very scripting language -like experience.
 
 
I have aimed to keep the list functions tail-recursive, the trade-off between a
speed loss from reversing lists and having support for arbitrary length lists
weighing towards the latter in my scales.
 
Some functions are implemented in a very combinatorial wanking -fashion and
should be rewritten for speed and clarity. Alternatively I could say that
they're good eta/beta-reduction tests for the compiler.
 
 
Latest news
-----------
  - working on other stuff, will try to trickle in bug fixes when found, along
    with extra tests
  - done with writing a more complete set of tests for src/prelude.ml
 
 
Examples
--------
 
open Prelude
 
(* my last modified file in /tmp *)
lsFull "/tmp" |> filter (eq (currentUid ()) @. fileUid) |> maximumBy mtime
 
(* concatenate files a, b and c into d *)
concatFiles "d" ["a"; "b"; "c"]
 
(* grep `find' output for AAC files *)
readCmd ["find"; "music"] |> lines |> filter (xmatch "\\.m4[ap]$")
 
(* fill a 100MB Bigarray with coreCount() parallel processes *)
bapinit Bigarray.char (fun i -> chr (Unix.getpid() mod 256)) (int 10e8)
 
(* blend two bytestrings together in parallel *)
bpzipWith average2 s1 s2
 
(* the speed gains here are likely non-existent, as forking and marshalling
   overheads dominate the compute-poor blending function *)
 
(* or written out as a parallel init that reads from the closure *)
bpinit (fun i -> ((buget s1 i) + (buget s2 i)) / 2) (min (blen s1) (blen s2))
 
 
As you may notice, the different collections have different prefixes for the
function names. List functions have no prefix, Array functions have 'a',
String functions have 's', Bytestring functions have 'b' and Bigarray
functions have 'ba'. Additionally, float functions use a 'f' suffix,
e.g. sumf [1.0; 2.0] vs. sum [1; 2].
 
There are PreList, PreArray, PreString and Bytestring modules for the
collections as well, but do note that they take some liberties with the
argument orders of some functions in the name of easier composition,
e.g. Array.init : int -> (int -> 'a) -> 'a array
 vs. PreArray.init : (int -> 'a) -> int -> 'a array.
 
 in map (PreArray.init id) (10--15)
and map (fun i -> Array.init i id) (10--15)
 
 
Development
-----------
http://www.github.com/kig/preludeml/tree/master
 
Contact
-------
Ilmari Heikkinen <ilmari.heikkinen@gmail.com>