
Hello all, in my program, I do stuff with predicates (a->Bool). For the most part this representation is just fine, but at the very end I need to convert a resulting predicate into a String so I can write it to a file. Wenn I represent my predicates as Lists or Sets, then this is doable and I am tempted to do it this way. The only other option I could come up with was to have a representation of "everything", which would in my case be large (10^8) but finite. Then I could construct a List or a Set at the very end, as [x | x<-everything, p x] without having explicit sets in the intermediate steps. I cannot see any other option, but I thought I better ask.

Depending on how you construct your predicates, you may be able to capture
their composition... And then serialise that.
For example:
If you were doing some sort of range intersection predicate construction ~
R1 n R2 n R3
Could be represented as a list of those ranges [(l1,r1),(l2,r2),(l3,r3)].
Basically, instead of constructing a predicate function directly, you would
assemble a data-structure representing the essence of the predicate, then
convert that to both a function for evaluation, as well as a string for
serialisation. This would also allow you to perform some "optimisation"
before serialisation which could be fun.
Do you have some examples of what the predicates look like?
- Lyndon
On Wed, Dec 23, 2015 at 8:55 PM, martin
Hello all,
in my program, I do stuff with predicates (a->Bool). For the most part this representation is just fine, but at the very end I need to convert a resulting predicate into a String so I can write it to a file.
Wenn I represent my predicates as Lists or Sets, then this is doable and I am tempted to do it this way. The only other option I could come up with was to have a representation of "everything", which would in my case be large (10^8) but finite. Then I could construct a List or a Set at the very end, as [x | x<-everything, p x] without having explicit sets in the intermediate steps.
I cannot see any other option, but I thought I better ask. _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

Am 12/25/2015 um 03:11 PM schrieb Lyndon Maydwell:
Depending on how you construct your predicates, you may be able to capture their composition... And then serialise that.
For example:
If you were doing some sort of range intersection predicate construction ~
R1 n R2 n R3
Could be represented as a list of those ranges [(l1,r1),(l2,r2),(l3,r3)]. Basically, instead of constructing a predicate function directly, you would assemble a data-structure representing the essence of the predicate, then convert that to both a function for evaluation, as well as a string for serialisation. This would also allow you to perform some "optimisation" before serialisation which could be fun.
Thanks, I understand I need a representation and a Set would be just one of the possiblilities.

You can store both values, a function and a string representation, in a
predicate:
data Predicate = Predicate (a -> Bool) String
And write corresponding Show instance to show string.
On Wed, Dec 23, 2015 at 2:55 PM, martin
Hello all,
in my program, I do stuff with predicates (a->Bool). For the most part this representation is just fine, but at the very end I need to convert a resulting predicate into a String so I can write it to a file.
Wenn I represent my predicates as Lists or Sets, then this is doable and I am tempted to do it this way. The only other option I could come up with was to have a representation of "everything", which would in my case be large (10^8) but finite. Then I could construct a List or a Set at the very end, as [x | x<-everything, p x] without having explicit sets in the intermediate steps.
I cannot see any other option, but I thought I better ask. _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
participants (3)
-
Kostiantyn Rybnikov
-
Lyndon Maydwell
-
martin