Prevent user to use binary operators defined in a new type

Viewed 117

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?

1 Answers

You can export the Polynomial type without exporting its constructors.

module Foo(Polynomial()) where

would do this.

Related