On Wed, Aug 28, 2013 at 12:16 PM, David Jeske <[email protected]> wrote:


> The cases I'm thinking of involve defining a new distinct type.. because I
> specifically want to prevent any implicit casts or operations on it. (Such
> as a "user-id" which happens to be an int, but for which increment a really
> bad thing to do)
>

I sort of suspected you had something like that in mind. In Haskell, the
thing you are looking for would be called NewType. I don't know whether
Haskell "lifts" all of the operations, though. That is: given Arith(int)
and deftype nt = NewType(int), is Arith(nt) now defined. I *think* the
Haskell specification says that all operations on the underlying type work
on the new type, but I'm not sure.

That said, these cases are handled easily enough by making a "struct UserID
> { int _id; }" which hides the details and AFAIK is just as efficient as
> passing around the original int.
>

Indeed. If you don't want operations to be lifted automatically, then
NewType is just a constructor for an unboxed parametric type:

unboxed struct NewType 'a
  elem : 'a


shap
_______________________________________________
bitc-dev mailing list
[email protected]
http://www.coyotos.org/mailman/listinfo/bitc-dev

Reply via email to