Why can't i re-use same value constructor among different data types?

前端 未结 2 1723
说谎
说谎 2021-01-18 01:00

i am new to Haskell and probably missing something really basic here, but i am not able to re-use same value constructor among different data types.

data Co         


        
2条回答
  •  不知归路
    2021-01-18 01:21

    There is no particular reason, that is how language was designed. I think the idea was to make sure compiler can infer type for as many expressions as possible. Note that if language will allow to reuse constructors, then you'll have to specify type for show Orange expression - compiler can't infer it anymore. Though now a lot of people don't take this reason seriously, and a lot of modern language extentions do break compiler's ability to infer types for many expressions. So I guess in few years you'll find that your example works already :)

提交回复
热议问题