throwing sugar into the void.

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

throwing sugar into the void.

Marc A. Ziegert
Hi@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?

(*)
<http://www.haskell.org/ghc/docs/latest/html/libraries/base/Foreign-Storable.html#v%3AsizeOf>
> 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

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: throwing sugar into the void.

Einar Karttunen
On 07.05 01:12, Marc A. Ziegert wrote:
> data Type a
> typeOf :: a -> Type a
> typeOf = undefined
> #define TYPE(a) (undefined::Type (a))
> ...
> sizeOf :: (Storable a) => Type a -> Int

I think the name Proxy is used for this in other places.

data Proxy a = Proxy
class Storable a where
    ...
    sizeOf :: Proxy a -> Int

proxy :: a -> Proxy a
proxy _ = Proxy

Note here that there are no undefined values used thus one does not need to be
careful with evaluation.

- Einar Karttunen
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe