maude-help AT lists.siebelschool.illinois.edu
Subject: Maude-help mailing list
List archive
- From: Traian Florin Şerbănuţă <traian.serbanuta AT fmi.unibuc.ro>
- To: Francesoc Bongiovanni <bongiovanni AT gmail.com>
- Cc: maude-help AT lists.cs.illinois.edu
- Subject: Re: [[Maude-help] ] higher order FILTER function
- Date: Fri, 22 Apr 2016 22:39:38 +0300
Hi Francesco,
Just a quick thought: as you probably already know, unlike map, filter does not modify the list, so you would have only one parameter, and have List{X} wherever you have List{Y} now.fmod FILTER{X :: TRIV} is
inc AP{X,Bool} .
pr LIST{X} .
var E : X$Elt .
var L : List{X} .
var F : Func{X,Bool} .
op filter : List{X} Func{X,Bool} -> List{X} .
eq filter(nil, F) = nil .
eq filter(E L, F) = if F[E] then E else nil fi
filter(L, F) .
endfm
fmod TEST is including FILTER{Nat} .
op odd : -> Func{Nat,Bool} .
var X : Nat .
eq odd[X] = not(2 divides X) .
op odds : List{Nat} -> List{Nat} .
var L : List{Nat} .
eq odds(L) = filter(L, odd) .
endfm
red odds(1 2 3 4 5 6 7 8 9 0) .
Hope this helps!
Traian
2016-04-22 17:42 GMT+03:00 Francesoc Bongiovanni <bongiovanni AT gmail.com>:
Hi there,
I am playing a bit with Maude and trying to implement the filter higher order
function based on some code for the MAP function I found on this archive a
long time ago.
fmod AP{X :: TRIV, Y :: TRIV} is
*** one param function
sort Func{X,Y} .
op _[_] : Func{X,Y} X$Elt -> Y$Elt [prec 17] .
*** no param function
sort FFunc{X} .
op _[] : FFunc{X} -> X$Elt [prec 17] .
endfm
fmod FILTER{X :: TRIV, Y :: TRIV} is
inc AP{X,Y} .
inc BOOL .
pr LIST{X} .
pr LIST{Y} .
var E : X$Elt .
var L : List{X} .
var F : Func{X,Y} .
op filter : List{X} Func{X,Y} -> List{Y} .
eq filter(nil, F) = nil .
ceq filter(E L, F) = E filter(L, F) if F[E] == true .
endfm
When I load the module, the interpreter does not expect E there...why? what I
am missing ?
Thanks in advance for your insights
- Francesco
- [[Maude-help] ] higher order FILTER function, Francesoc Bongiovanni, 04/22/2016
- Re: [[Maude-help] ] higher order FILTER function, Traian Florin Şerbănuţă, 04/22/2016
- Re: [[Maude-help] ] higher order FILTER function, Francesoc Bongiovanni, 04/25/2016
- Re: [[Maude-help] ] higher order FILTER function, Traian Florin Şerbănuţă, 04/22/2016
Archive powered by MHonArc 2.6.16.