0

Say I have such sum type

data YesOrNo = Yes | No

If somehow I have a value of this type in GHCI

>:t yOrN
yOrN :: YesOrNo

Is it possible to get the data type of this value so that I know if it's a Yes or a No?

Context:

I'm using a library that returns a sum type of 10+ types https://hackage.haskell.org/package/bson-0.3.2.3/docs/Data-Bson.html#t:Value

Now I have a value of this type, I would like to know which data type exactly is that value.

Leo Zhang
  • 3,040
  • 3
  • 24
  • 38
  • You may check with a function like `Data.Bool.bool No Yes . (Yes ==)` – Redu Sep 23 '17 at 22:29
  • 2
    The data type is `YesOrNo`, as reported by ghci. You want to know which constructor was used, which you can do by pattern matching. – melpomene Sep 23 '17 at 22:35
  • 3
    `Yes` and `No` are not types, but values. Use `case yOrN of Yes -> ... ; No -> ....` to check the value, or other forms of pattern matching. – chi Sep 23 '17 at 23:01

0 Answers0