haskell - Adding a new constructor to a datatype after declaration -


i have requirement add new constructors datatype after it's module has been loaded. pseudo code may seem this:

import mymodule  data mytype = newconstructor 

in above example mytype has been defined in mymodule. there way that?

you can't. datatype closed. , thing otherwise, how can predict how previsouly defined function behave?

several workarounds exist, here off top of head:

  1. use function constructor. e.g. myextendedtype = mytype 42;
  2. use own type , mapping function. e.g. data myextendedtype = myextendedtype; tomytype myextendedtype = mytype 42;
  3. wrap existing datatype:

    import mymodule old  data myextendedtype = fromold (mytype int) | myextendedtype  foo (fromold m) = old.foo m foo myextendedtype = undefined 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -