<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi Jon, <div class="">thanks for that speedy response - looks ideal!</div><div class=""><br class=""></div><div class="">I guess though that any tests for module Tee will have to be written inside Tee,</div><div class="">rather than in a separate test file - again this is no big deal.</div><div class=""><br class=""></div><div class="">Regards, Andrew</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 19 May 2017, at 10:10, Jon Purdy <<a href="mailto:evincarofautumn@gmail.com" class="">evincarofautumn@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">I believe you can use unidirectional pattern synonyms, and only export the patterns, not the constructors.<div class=""><br class=""></div><div class="">{-# LANGUAGE PatternSynonyms #-}</div><div class="">module Tee (T, t1, t2, pattern T1, pattern T2) where</div><div class=""><br class=""></div><div class="">data T = MkT1 Bool | MkT2 Int | …</div><div class="">pattern T1 a <- MkT1 a</div><div class="">pattern T2 a <- MkT2 a</div><div class="">…</div><div class="">t1 :: Bool -> T</div><div class="">t2 :: Int -> T</div><div class="">…</div><div class=""><br class=""></div><div class="">You can pattern-match on T1 just fine, but if you try to use it as a constructor you’ll get “non-bidirectional pattern synonym ‘T1’ used in an expression”.</div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Fri, May 19, 2017 at 1:43 AM, Andrew Butterfield <span dir="ltr" class=""><<a href="mailto:Andrew.Butterfield@scss.tcd.ie" target="_blank" class="">Andrew.Butterfield@scss.tcd.ie</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">All,<br class="">
<br class="">
 is there any way in Haskell to export a *data* type so that importing modules can pattern match,<br class="">
but not use the constructors to build anything?<br class="">
<br class="">
My use case is an AST with invariant - I want the convenience of pattern matching<br class="">
with the safety of having to build using functions exported by the model rather than the constructors directly.<br class="">
<br class="">
 e.g<br class="">
<br class="">
given<br class="">
<br class="">
data T = T1 Bool | T2 Int | TT T T<br class="">
t1 :: Bool -> T<br class="">
t2 :: Int -> T<br class="">
tt :: T -> T -> T<br class="">
<br class="">
from outside I can write<br class="">
<br class="">
f(T1 False) =  tt (t1 True) (t2 42)<br class="">
<br class="">
but not<br class="">
<br class="">
f(T1 False) = TT (T1 True) (T2 42) ?<br class="">
<br class="">
<br class="">
Regards,<br class="">
<br class="">
Andrew Butterfield<br class="">
School of Computer Science & Statistics<br class="">
Trinity College<br class="">
Dublin 2, Ireland<br class="">
<br class="">
______________________________<wbr class="">_________________<br class="">
Haskell-Cafe mailing list<br class="">
To (un)subscribe, modify options or view archives go to:<br class="">
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank" class="">http://mail.haskell.org/cgi-<wbr class="">bin/mailman/listinfo/haskell-<wbr class="">cafe</a><br class="">
Only members subscribed via the mailman list are allowed to post.</blockquote></div><br class=""></div>
</div></blockquote></div><br class=""><div class="">
<div class=""><div class="">Andrew Butterfield</div><div class="">School of Computer Science & Statistics</div><div class="">Trinity College</div><div class="">Dublin 2, Ireland</div></div>

</div>
<br class=""></div></body></html>