datatype (atoms: 'a) rexp =
is_Zero: Zero |
is_One: One |
Symbol "'a ⇒ bool" |
Plus "('a rexp)" "('a rexp)" |
Times "('a rexp)" "('a rexp)" |
Star "('a rexp)"
I have defined regular expression type, but I found the function of map_rexp, rexp.map_compare both failed.
Why does this happen, how to fix it.
And I am sure that you tried your example, reduced it (by removing branches) until map was generated. So you realized that the problem is Symbol "'a ⇒ bool".
So what was the question?
My initial idea is the Symbol means a predicate, take any input, then return a boolean value.
Is that such definition not work in the datatype context
how would you define it?
Your map has type ('a ⇒ 'b) ⇒ 'a rexp ⇒ 'b rexp
how would you convert a function 'a ⇒ bool?
This is a real question, I have absolutely no clue
if the type was ('a ⇒ 'a) ⇒ 'a rexp ⇒ 'a rexp then I can image function composition in Symbol, but not here
I have seen an example datatype ('a, 'b) ite = ITE "'a ⇒ bool" "'a ⇒ 'b" "'a ⇒ 'b" here
it takes a predicate in the condition
Sorry for unfamilr with the type function
maybe this would work, if you have any suggestion.
datatype (atoms:'a, 'b) rexp =
is_Zero: Zero |
is_One: One |
Symbol "'a ⇒ bool" |
Plus "('a, 'b) rexp" "('a, 'b) rexp" |
Times "('a, 'b) rexp""('a, 'b) rexp" |
Star "('a, 'b) rexp"
Then you should report this to the mailing list…
maybe @Martin Desharnais or @Dmitriy Traytel know why adding a second type parameter makes the map function work suddenly
I do not think it is possible to generate such a map function. As Mathias said: How would such a function look.
Note that the map function for your ITE example only maps over the return types of the functions (the 'bs). There is no mapping over the 'as happening there
that what I though too, but for the second version with the 'b it works…
(but I did not check how the definition looks like)
It does generate a map function, but only one mapping over the second type argument.
"map_rexp" :: "('a ⇒ 'b) ⇒ ('c, 'a) rexp ⇒ ('c, 'b) rexp
Last updated: Nov 13 2025 at 04:27 UTC