Felix has a second kind of functional list: an ralist.
This is a list with log N indexed access: a slowish kind of array if you like,
but purely functional.
The problem is that this data types is represented by functions.
So there's a ralist_head, and ralist_tail, and an ralist_empty function
for decoding, but we cannot pattern match on that!
So we could do this:
let ?pat =
if ralist_empty x then None[T]
else Some (ralist_head x, ralist_tail x)
in match pat with
| None => /* Empty case */
| Some (?h,?t) => /* Cons case */
endmatch
instead, but that only works if its the *top level*. If we want to match
(x, ra, opt[ra[T])
or something we'd be writing a lot of prolog, and have to redesign
the pattern. And what is we wanted to match like
| Cons (?x, Cons (_, Con (22), Empty)) => ..
My thought on a solution is something like this:
. f -> pat
This means, for the component of the match argument in the position
of this pattern, apply function f to it, and match the result against pat.
For example
match ra with
| . (fun (x:ralist) => if ralist_empty x then None
else Some (ralist_head x, ralist_tail x) )
-> None => ...
| . (fun (x:ralist) => if ralist_empty x then None
else Some (ralist_head x, ralist_tail x) )
-> Some (?h,t) => ...
endmatch
Unfortunate duplication though. In this case we could write:
match ra with
| . ralist_empty -> true => ...
| (.ralist_head, .ralist_tail) -> ?h,?t => ..
however in general that wouldn't be safe. Generally duplications
can't be avoided anyhow, for example:
match (x,y) with
| 1,2 => ..
| 1,3 => ..
compares the first component to 1 twice.
What does C# do? F#? Scala? Any ideas?
--
john skaller
[email protected]
http://felix-lang.org
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language