[Haskell-cafe] Fwd: Increasing Haskell modularity

Gesh gesh at gesh.uni.cx
Wed Oct 1 22:05:35 UTC 2014


On 10/1/2014 11:42 PM, Bardur Arantsson wrote:
> (I say "proposal"... this needs some serious fleshing out and a
> semi-formal specification for instance resolution rules &c before it
> becomes a proposal. Just "Look at Oleg's paper" is not good enough.)
I see I came off unclearly. Please allow me to remedy that.

My reference to Oleg's paper was badly framed. What I meant to say was
more along the following lines:
Oleg discussed adding local typeclass instances in his reflection paper.
For some reason, his proposal wasn't taken. (Does anyone know why?)
I'd like to suggest something along similar lines:
Allow instances in let-expressions and where-clauses. These instances
shadow other instances with the same parameter list.
Similarly, instances defined in modules shadow imported instances.

Thus, in the following program:
 > module Foo where
 > import Bar (Baz) -- Where Bar defines instance Show (Baz a)
 > instance Show (Baz a) where -- shadows the imported instance
 > foo = let instance Show (Baz a) where -- shadows the instance defined
 >       in ...              -- in where below, just like other bindings
 >   where instance Show (Baz a) -- shadows the module-global instance
 >         instance Show (Baz Quz) -- only allowed with
 >         -- OverlappingInstances, isn't shadowed by any of the other
 >         -- instances in this example.

In this example, the instances for Baz have the following scopes:
* From Bar: Nowhere, as it is immediately shadowed.
* From Foo: Within all top-level declarations besides foo, as foo's
             where clause shadows it.
* From the where clause: Within the where clause. The instance for
                          Baz Quz is also visible within the let
                          expression, as it is not shadowed by it.
* From the let expression: Within the let expression.

Basically all I'm doing is applying regular name resolution semantics
to instances with the same parameter lists.

I hope this helps clarify things. If not, please tell me what needs to
be done to fully clarify this.

Gesh


More information about the Haskell-Cafe mailing list