Stéphane Laurent
Stéphane Laurent

Reputation: 84529

Prevent user to use binary operators defined in a new type

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?

Upvotes: 1

Views: 155

Answers (1)

Louis Wasserman
Louis Wasserman

Reputation: 198133

You can export the Polynomial type without exporting its constructors.

module Foo(Polynomial()) where

would do this.

Upvotes: 2

Related Questions