Hello,
>>>>> "Gabor" == Gabor Greif <[EMAIL PROTECTED]> writes:
Gabor> I am wondering if it would be feasible to declare laws that
Gabor> are guaranteed to hold for some objects in a Haskell-like
Gabor> functional language.
I think that's such an important point that extensions of the
language are appropriate.
Gabor> For example I would like to declare that (+) is
Gabor> commutative. This would have the benefit, that the compiler
Gabor> could optimize the parameter passing to a commutative
Gabor> function by not having to swap arguments on the stack:
Not to forget associativity! This would allow a compiler
to parallelize the fold and scan functions which could have
a great impact on the execution time.
Gabor> even when (==) was no builtin primitive.
Of course!
Gabor> A convenient (Haskellish) syntax I could come up with is:
>> property Commutative f where f a b = f b a
>>
>> instance Commutative (==) instance Commutative (+) :: Int -> Int
The type is important here. Properties sometimes are not compatible with
the class hierarchy.
>> instance Isomorhism (f, g) where
>> f x = (+x)
>> g x = (+(-x))
Gabor> Of course in both where clauses "x" must stand for the same
Gabor> object.
I don't understand what you mean. Both occurrences of "x" are bound
by the function definition and are therefore not visible outside.
Gabor> Does this all make sense?
Yes! Thank you for taking this interesting point into discussion.
I think Haskell should develop in a way that properties of
functions can be defined, especially when the functions are implemented
in a foreign language and thus not belong to the compiler's knowledge.
Yet another mechanism to pass information to the
compiler/interpreter like is known from `seq` and `par`
or trace. Maybe, one should consider if there exists a general sound
scheme to pass compile-time information from the source text maybe to ghc,
maybe just through ghc towards other compilers like C compilers.
A general scheme would allow the user to make experiments with new
things without being hindered by the effort to hack inside ghc.
At the moment, I'm using special comments [Int,{-! 5 !-}], e.g.,
to tell a preprocessor that a list always has length 5 but I don't
like to use such methods for the far future.
Sincerely
-------------------------------------------------------------------------------
Christoph Herrmann
E-mail: [EMAIL PROTECTED]
WWW: http://brahms.fmi.uni-passau.de/cl/staff/herrmann.html