2

Consider I have:

data family P a
data instance P () = C1 (S.Set Int) | C2 -- and may be other constructors

let x = C1 (S.fromList mempty)
    y = C2

Is it a way to write a function which is able to get from x a String "C1" and from y - "C2"? Like:

cstrStringName :: ... -> String
cstrStringName = ...
RandomB
  • 3,367
  • 19
  • 30
  • 3
    This question sets off some alarm bells in my head. I strongly encourage you to find a Haskell expert to chat with and describe what you're trying to do and why you think that needs you to know a constructor's name as a `String`. It may be that there's a better or more idiomatic way to meet your needs, though you may need to take one or two steps back in your program design to find it. – Daniel Wagner Nov 23 '22 at 16:39
  • @Iceland_jack The community has many mechanisms for chatting with experts. There is a very active IRC channel that is likely sufficient for something like this; or, for more substantive conversations, there are consultants available for hire. (And of course SO itself is a resource, if you can phrase your conversation in a way that doesn't require multiple rounds of communication.) – Daniel Wagner Nov 23 '22 at 17:14
  • the idea was to create a newtype that add uniqueness to Set items based on their constructor, not on the default Ord, Eq instances that include the "content" (arguments) of the constructors as well. I done it already and it work as I expected. Another option is to use Map instead of but in this case key will be "unbound" (allows any permutations between keys/values) from the values that I don't like. – RandomB Nov 24 '22 at 04:59

0 Answers0