[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
'deriving' in Haskell 'interface's
Original-Via: uk.ac.ukc; Fri, 19 Oct 90 19:37:30 BST
From: Kent Karlsson <kent>
Date: Fri, 19 Oct 90 17:18:55 +0100
To: haskell@cs.glasgow.ac.uk
Subject: 'deriving' in Haskell 'interface's
Original-Sender: kent%se.chalmers.cs@sunic.sunet.se
Sender: haskell-request@cs.glasgow.ac.uk
DERIVING IN INTERFACES
======================
The report says on p. 42 that data declarations (where the
constructors are exported...) that have derived instances should
retain the 'deriving' part in the interface.
1. That is not very elegant, nor very general. Instead, let
derived instances have an explicit 'instance' declaration
in the interface, just like any other instance declared in
the corresponding module. 'deriving' should only be a
convenience for the programmer.
2. Any (see point 3) optimization advantages of "knowing" that
an instance is derived can, if desired, be obtained by having
a pragma, e.g.
{-:DERIVED:-}
instance Text My_New_Type
3. Currently 'instance' declarations in interfaces should not
have a 'where'-part. However it might be nice to have a
"natural" place to put pragmas referring to specific methods,
e.g. strictness annotations. So why not let instance declarations
in interfaces have a where-part with the types of the methods,
whether the instance is derived or not.
E.g.
instance Text My_New_Type where
showsPrec :: Int -> My_New_Type -> ShowS {-:TTF,F:-}
readsPrec :: Int -> ReadS My_New_Type {-:TF,F:-}
...
(The "{-:TTF,F:-}" examplifies a pragma, it's hbc's way of
writing strictness annotations.) The annotations may be different
for different instances of the same class, so they cannot be
placed in the class declaration.
/kent k