[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 'deriving' in Haskell 'interface's]



To: haskell@cs.glasgow.ac.uk
Cc: simonpj@cs.glasgow.ac.uk
Subject: Re: 'deriving' in Haskell 'interface's]
Date: Fri, 09 Nov 90 15:06:17 +0000
From: Simon L Peyton Jones <simonpj@cs.glasgow.ac.uk>
Sender: haskell-request@cs.glasgow.ac.uk


Kent sent a message about "deriving clauses" in interfaces, a long time
ago.  I replied, but it got lost.  So here's a resend.  Sorry for the
delay.

Simon


| Date:         Fri, 19 Oct 90 17:18:55 +0100
| From: Kent Karlsson <kent%cs.chalmers.se%YALECS.BITNET@yalevm.ycc.yale.edu>
| Subject:      'deriving' in Haskell 'interface's
| To: Multiple recipients of list HASKLD-L <HASKLD-L@YALEVM.BITNET>
| 
|                 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

I basically agree with this.  The reason we specified that derived
instances should be specified with a deriving clause was an efficiency
one: there might be some efficiency gain.  But that's exactly what pragmas
are for: to give extra redundant information which can increase 
efficiency.  

Still, it would be nice to be able to use a deriving clause in an
interface, if only for brevity.  The written-out instances can
be rather long.

| 
| 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.
| 

An efficiency thing again, so pragmas are the right solution, but the
extra info belongs entirely in the pragma:

	instance Text My_New_Type
		{-#METHODS showsPred: TTF,F ; readsPred: TF,F -}