[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Alain Frisch <frisch@c...> |
| Subject: | Re: list composition functions |
On 16 Oct 2000, Julian Assange wrote:
> Imagine you have the follow three functions,
>
> let mirror x = [x;x]
> let plus1 x = [x+1]
> let none x = []
>
> I'm trying to define an operator (>>) that will then operate like so
>
> (mirror >> mirror >> plus1) [1]
>
> [2;2;2;2]
You could try something like:
let build_transformer f x =
List.concat (List.map f x)
let (>>) t1 t2 x =
t1 (t2 x)
let mirror = build_transformer (fun x -> [x;x])
let plus1 = build_transformer (fun x -> [x+1])
let none = build_transformer (fun x -> [])
(mirror and none are not generalized since their definition
is expansive)
--
Alain Frisch