<div dir="ltr">Yes.  In Haskell, types are your friends.  You should define new types liberally.<div><br></div><div>I think the usual approach is to create newtype wrapper:<div><br></div><div>> module EmailAddr (EmailAddr, mkEmailAddr) where</div>
<div>></div><div>> newtype EmailAddr = EmailAddr String</div><div>></div><div>> mkEmailAddr :: String -> Maybe EmailAddr</div><div>> mkEmailAddr str = if isEmailAddr then Just (EmailAddr str) else Nothing</div>
<div><br></div><div>The only way to make an EmailAddr is via the mkEmailAddr function, which checks that the string is actually a valid address (implementation omitted).  Therefore, there's a guarantee that any EmailAddr is actually a well-formed email address, and any functions that operate on an EmailAddr can rely upon this.</div>
<div><br></div><div>Of course, it might be useful to create an actual algebraic type instead:</div><div><br></div><div>> data EmailAddr = EmailAddr { address :: String, domain :: String }</div><div><br></div><div>(and the domain could similarly be an algebraic type instead of a plain string)</div>
<div><br></div><div>In general, you should be working with types that closely reflect the domain you're working in.  This will make your functions more clear, and the compiler/type checker will be able to provide more help during development.</div>
</div><div><br></div><div>John L.</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Mar 1, 2014 at 4:35 AM, KwangYul Seo <span dir="ltr"><<a href="mailto:kwangyul.seo@gmail.com" target="_blank">kwangyul.seo@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">In Java, the Checker Framework (<a href="http://types.cs.washington.edu/checker-framework/" target="_blank">http://types.cs.washington.edu/checker-framework/</a>) provides a way to type check string literals. For example, Java signatures type system differentiates strings literals in different forms:<div>

<br></div><div>1. Unqualified strings : </div><div>"Hello, world!" -> @Unqualified String</div><div><div><br></div><div>2. Fully qualified names: </div><div>"package.Outer.Inner" -> @FullyQualifiedString String</div>

</div><div><br></div><div>3. Binary names: </div><div>"package.Outer$Inner" -> @BinaryName String<br></div><div><br></div><div>4. Field descriptors: </div><div>"Lpackage/Outer$Inner;" -> @FieldDescriptor String<br>

</div><div><br></div><div>It can do the similar checks with regular expressions or SQL statements.<br></div><div><br></div><div>Is it possible to type check string literals in Haskell? I think it would be nice if we can check if a given string literal is a valid URL or an email address at compile time.</div>

<div><br></div><div>Regards,</div><div>Kwang Yul Seo</div><div><br></div></div>
<br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br></div>