Home > OS >  Prevent user to use binary operators defined in a new type
Prevent user to use binary operators defined in a new type

Time:07-24

I'm currently trying to define multivariate polynomials over a field in Haskell (work in progress). I have as a starting point:

data Polynomial a = Zero
                  | M (Monomial a)
                  | Polynomial a : : Polynomial a
                  | Polynomial a :*: Polynomial a
                    deriving (Show)

Is it possible to prevent the user to use the binary operators : : and :*:? I'd like, because I define the addition and the multiplication later, which not only perform the operation but also put the result in canonical form (sum of monomials with distinct powers), and I would like that the user can only use these operations.

I would bet that's not possible if one exports the Polynomial type, but maybe the brilliant minds here have a trick?

CodePudding user response:

You can export the Polynomial type without exporting its constructors.

module Foo(Polynomial()) where

would do this.

  • Related