
Hi all, Is it possible to export constructors from a module in a way that they can be used for pattern matching but not for creating types? Patrick -- ===================== Patrick LeBoutillier Rosemère, Québec, Canada

On Thursday 24 March 2011 13:17:16, Patrick LeBoutillier wrote:
Hi all,
Is it possible to export constructors from a module in a way that they can be used for pattern matching but not for creating types?
Patrick
No, that's impossible (as far as I know). If a constructor is exported, it's available for construction as well as for pattern matching.

On Thu, Mar 24, 2011 at 08:17:16AM -0400, Patrick LeBoutillier wrote:
Hi all,
Is it possible to export constructors from a module in a way that they can be used for pattern matching but not for creating types?
I would suggest exporting an 'eliminator' function for your data type (like the functions 'maybe' and 'either'), which essentially allows the user to do pattern-matching (although not with built-in pattern matching syntax). For example, if your data type is data Foo = Bar Int | Baz Foo Char | Quux then you could export a function matchFoo :: Foo -> (Int -> a) -> (Foo -> Char -> a) -> a -> a which they could use like matchFoo f (\i -> ...) -- Bar case (\f' c -> ...) -- Baz case ... -- Quux case -Brent
participants (3)
-
Brent Yorgey
-
Daniel Fischer
-
Patrick LeBoutillier