<div dir="ltr">ok ... by using "newtype", we are constricting/constraining to a subset of CInt .. e.g. something like a "subtype" of CInt?? (where by "subtype", I mean like the notion of subtype in languages like Ada). For our audience, can you perhaps distinguish (in a typeful way) between the Haskell notion of "type", "newtype" and "data"? Or maybe let's distinguish between these notions not only in a typeful manner, but also in a historical motivation? .. ... motivations are always IMO very, very enlightening! <br>
<br><br>Regards, vasili<br><br><div class="gmail_quote">On Mon, Oct 6, 2008 at 12:47 AM, Don Stewart <span dir="ltr"><<a href="mailto:dons@galois.com">dons@galois.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Used wisely, newtype prevents accidentally constructing illegal values<br>
of Signal type, by treating them as CInts. You can restrict the valid<br>
values of the Signal type to be just those signals you define, not<br>
arbitrary bit patterns that fit in a CInt.<br>
<br>
vigalchin:<br>
<div class="Ih2E3d">> Thanks Don. Maybe both for me and others in order to take the fight to the<br>
> Klingons and other Baddies, please explain the "typefulness" protection<br>
> that "newtype" affords over the "Klingon " "type" ... In the code that I<br>
> contributed to the library, I like to think that I used "newtype"<br>
> appropriately but not perhaps with full understanding.<br>
><br>
> Thanks, Vasili<br>
><br>
</div><div class="Ih2E3d">> On Mon, Oct 6, 2008 at 12:37 AM, Don Stewart <[1]<a href="mailto:dons@galois.com">dons@galois.com</a>> wrote:<br>
><br>
> vigalchin:<br>
> > Hello,<br>
> ><br>
> > I am reading some extant Haskell code that uses Posix<br>
> signals.... I am<br>
> > confused by the motivation of the following ...<br>
> ><br>
> > type [1]Signal = [2]CInt<br>
> > [3]nullSignal :: [4]Signal<br>
> > [5]internalAbort :: [6]Signal<br>
> > [7]sigABRT :: [8]CInt<br>
> > [9]realTimeAlarm :: [10]Signal<br>
> > [11]sigALRM :: [12]CInt<br>
> > [13]busError :: [14]Signal<br>
> > [15]sigBUS :: [16]CInt<br>
> ><br>
> > OK .. "type" is really just a synomym and doesn't invoke type<br>
> checking<br>
> > like "data" type declarations do .. so why don't we have all the<br>
> "CInts"<br>
> > substituted by "Signal"? I.e. what did I miss?<br>
><br>
> Looks like it should all be Signal, and probably should be using a<br>
> newtype, to prevent funky tricks. The Posix layer is a bit crufty.<br>
> -- Don<br>
><br>
</div>> References<br>
><br>
> Visible links<br>
> 1. mailto:<a href="mailto:dons@galois.com">dons@galois.com</a><br>
</blockquote></div><br></div>