[clean-list] Instances for functions (was: Low-level graphics under Windows)
Ronny Wichers Schreur
ronny@cs.kun.nl
Thu, 11 Jan 2001 18:52:01 +0100
Jerzy Karczmarczuk writes:
>I tried to overload (+) (*) etc for functions [...] It seems
>that this bombs under Windows.
Are you using the latest Clean compiler (1.3.3)? There's a
problem in earlier releases with the label generation for
instances for function types. We fixed this bug, but Sjaak
Smetsers told me that these instances are not really supported.
I don't know what the exact status is, nor if they will be
supported in Clean 2.0.
The following example works with Clean 1.3.3:
class ftrace a :: !message .a -> .a | toString message
// instance for function types: trace the result
instance ftrace (a -> b) | ftrace b where
ftrace message function
= \value -> ftrace message (function value)
// generic instance for values: use normal trace
instance ftrace a where
ftrace message value
= trace message value
The idea is that you can trace a function when it returns
its value, such that
map (ftrace "id -> " id) [1, 2] prints [id -> 1, id -> 2]
whereas
map (trace "id -> " id) [1, 2] prints [id -> 1, 2]
>End of clean-list Digest
Cheers,
Ronny Wichers Schreur