Stream: Beginner Questions

Topic: Why does map_t function fails


view this post on Zulip Hongjian Jiang (Jul 25 2023 at 13:08):

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.

view this post on Zulip Mathias Fleury (Jul 25 2023 at 13:18):

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".

view this post on Zulip Mathias Fleury (Jul 25 2023 at 13:18):

So what was the question?

view this post on Zulip Hongjian Jiang (Jul 25 2023 at 13:21):

My initial idea is the Symbol means a predicate, take any input, then return a boolean value.

view this post on Zulip Hongjian Jiang (Jul 25 2023 at 13:21):

Is that such definition not work in the datatype context

view this post on Zulip Mathias Fleury (Jul 25 2023 at 13:22):

how would you define it?

view this post on Zulip Mathias Fleury (Jul 25 2023 at 13:23):

Your map has type ('a ⇒ 'b) ⇒ 'a rexp ⇒ 'b rexp

view this post on Zulip Mathias Fleury (Jul 25 2023 at 13:23):

how would you convert a function 'a ⇒ bool?

view this post on Zulip Mathias Fleury (Jul 25 2023 at 13:23):

This is a real question, I have absolutely no clue

view this post on Zulip Mathias Fleury (Jul 25 2023 at 13:24):

if the type was ('a ⇒ 'a) ⇒ 'a rexp ⇒ 'a rexp then I can image function composition in Symbol, but not here

view this post on Zulip Hongjian Jiang (Jul 25 2023 at 13:26):

I have seen an example datatype ('a, 'b) ite = ITE "'a ⇒ bool" "'a ⇒ 'b" "'a ⇒ 'b" here

view this post on Zulip Hongjian Jiang (Jul 25 2023 at 13:27):

it takes a predicate in the condition

view this post on Zulip Hongjian Jiang (Jul 25 2023 at 13:27):

Sorry for unfamilr with the type function

view this post on Zulip Hongjian Jiang (Jul 25 2023 at 13:30):

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"

view this post on Zulip Mathias Fleury (Jul 25 2023 at 13:34):

Then you should report this to the mailing list…

view this post on Zulip Mathias Fleury (Jul 25 2023 at 13:35):

maybe @Martin Desharnais or @Dmitriy Traytel know why adding a second type parameter makes the map function work suddenly

view this post on Zulip Simon Roßkopf (Jul 25 2023 at 16:55):

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

view this post on Zulip Mathias Fleury (Jul 25 2023 at 17:26):

that what I though too, but for the second version with the 'b it works…

view this post on Zulip Mathias Fleury (Jul 25 2023 at 17:26):

(but I did not check how the definition looks like)

view this post on Zulip Simon Roßkopf (Jul 25 2023 at 17:43):

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: Apr 28 2024 at 08:19 UTC