[Haskell-cafe] throwing sugar into the void.

Marc A. Ziegert coeus at gmx.de
Sat May 6 19:12:30 EDT 2006

Hi at all!

I'd like to hear some comments about the following ideas; maybe they are someway obsolete or even useless nonsense.

A few days ago, I thought about abstracting the instance of an object away, like used in Foreign.Storable.sizeOf::(Storable a)=>a->Int, where only the type of an object is used.
The problem with the function sizeOf is, that the result should be constant per definition(*), but how can we make the compiler know this?

> sizeOf::a->Int
>     "Computes the storage requirements (in bytes) of the argument. The value of the argument is not used." 

So I thought we may need a new (abstract) datatype to wrap the type of an object, just to contain no dynamic data:

data Type a
typeOf :: a -> Type a
typeOf = undefined
#define TYPE(a) (undefined::Type (a))
sizeOf :: (Storable a) => Type a -> Int

Maybe this is a little bit too ugly and cumbersomely, just to make sizeOf constant.
This version of sizeOf is not really comfortable anymore; but it isn't comfortable to write "(undefined::a)", too.
To be able to write "(::a)" instead, would be really nice, IMHO; but how about "(_::a)"?

<trying to be equivocating>
 undefined is another way to implement ...nothing.
</trying to be equivocating>
More comfortable would it be to write a single symbol instead of the long word "undefined":

_ :: a
_ = undefined

Using "_" as a function should not be such a problem: it cannot be mixed with the joker "_" as parameter.
To define this function may be a problem: It needs a compiler-patch to allow this, ATM.

By the way, this symbol is not used at type-level... How about praefix/postfix operators instead of only infix?

-- praefix
newtype BigLambda a = BigLambda a
(/\) :: _ -> a -> BigLambda a
/\ a = BigLambda a

-- postfix
newtype Lifted a = Lifted a
(!^) :: a -> _ -> Lifted a
a !^ = Lifted a

May this be confusing? Or even impossible? Am I insane?
Well, I don't know how hard it would be to implement those language features. I would not like to make anyone implement all this, if it is only a niceToHave-butIDontUseIt, like the implicit parameters feature.

- marc

More information about the Haskell-Cafe mailing list