Allow multiple data constructor declarations

I am currently experimenting with data types, and I ran into a problem with multiple data constructor declarations.

data DBPosition = Unknown
                | Omega Integer
                | Delta Integer
                deriving (Show, Eq, Ord)

data DBGeometry = Unknown | Cis | Trans
                deriving (Show, Eq, Ord)

data DoubleBond = DoubleBond DBPosition DBGeometry
                deriving (Show, Eq, Ord)

If I needed to make such a value - let bond = DoubleBond Unknown Unknownthen it would be possible to assume that the first Unknownis of type DBPositionand the second Unknownis of type DBPosition. Unfortunately, this is not the case:

test.hs:6:27:
Multiple declarations of `Unknown'
Declared at: test.hs:1:27
             test.hs:6:27
Failed, modules loaded: none.

Are there any language extensions that can be used to get around this?

+4
source share
1 answer

, , . , , UnknownDBPosition UnknownDBGeometry. , :

  • , , , , - ;
  • , Unknown .

, Unknown Maybe, .

data DBPosition = Omega Integer
                | Delta Integer
                deriving (Show, Eq, Ord)

data DBGeometry = Cis | Trans
                deriving (Show, Eq, Ord)

data DoubleBond = DoubleBond (Maybe DBPosition) (Maybe DBGeometry)
                deriving (Show, Eq, Ord)
+9

Source: https://habr.com/ru/post/1605875/


All Articles