<html>
<head>
<meta http-equiv="content-type" content="text/html;
charset=windows-1252">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Hi All, <br>
<br>
My apologies if this is not the right forum, but am not satisfied
with my current understanding.<br>
<br>
I am surprised that this program compiles in GHC: <br>
<br>
-----<br>
data UserSupplied = UserSupplied -- i.e. unsafe<br>
data Safe = Safe<br>
<br>
data Username a = Username { first :: String, last :: String}<br>
<br>
sanitize :: Username UserSupplied -> Username Safe<br>
sanitize name = name { first = "John" }<br>
<br>
main = putStrLn "Hi!"<br>
-----<br>
<br>
My trouble is that it seems the record syntax is<b
class="moz-txt-star"><span class="moz-txt-tag"></span><span
class="moz-txt-tag"></span></b> *implicitly* converting from one
type to the other. It seems I would have to remove the phantom type
by adding a tag to avoid this: <br>
<br>
-----<br>
data Username a = Username { first :: String, last :: String, tag ::
a }<br>
<br>
sanitize :: Username UserSupplied -> Username Safe<br>
sanitize name = name { first = "John" } -- FAIL as expected!! :-)<br>
-----<br>
<br>
But this makes me unwilling to use phantom types for security as I
would be worried of unwittingly making the conversion.<br>
<br>
Could somebody sprinkle some insight into why this is "converted
automatically" for phantom types?<br>
Is there another way around this? <br>
<br>
<br>
Thanks! <br>
<br>
<br>
Dimitri <br>
<br>
<br>
</body>
</html>