Re: Local definitions in the class instances

2011-02-02 Thread Max Bolingbroke
On 2 February 2011 02:25, Sebastian Fischer wrote: > It's a nice trick! Although it does look strange, it may be reasonable to > allow pattern bindings in instance declarations regardless of the original > proposal. Is it correct that, currently, pattern bindings are allowed > everywhere but in in

Re: Local definitions in the class instances

2011-02-01 Thread Sebastian Fischer
On Tue, Feb 1, 2011 at 9:23 PM, Ben Millwood wrote: > On Tue, Feb 1, 2011 at 9:52 AM, Max Bolingbroke > wrote: > > > > Local declarations at module scope can be emulated using pattern > bindings: > > > > """ > > (foo, bar) = (foo, bar) > > where > >foo = .. > >bar = .. > >private = .

Re: Local definitions in the class instances

2011-02-01 Thread Ben Millwood
On Tue, Feb 1, 2011 at 9:52 AM, Max Bolingbroke wrote: > > Local declarations at module scope can be emulated using pattern bindings: > > """ > (foo, bar) = (foo, bar) >  where >    foo = .. >    bar = .. >    private = ... > """ > > If instance declarations supported pattern bindings you could ge

Re: Local definitions in the class instances

2011-02-01 Thread Max Bolingbroke
On 27 January 2011 17:11, Iavor Diatchki wrote: > instance Num Wrapped where >    local >      lift2 f (Wrapped a) (Wrapped b) = Wrapped (f a b) >      lift f (Wrapped a) = Wrapped (f a) >    in >     (+) = lift2 (+) >     (-) = lift2 (-) >     (*) = lift2 (*) >     abs = lift abs >     signum = l

Re: Local definitions in the class instances

2011-01-30 Thread Brandon S Allbery KF8NH
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 1/30/11 05:54 , John Meacham wrote: >> instance Num Wrapped where >> (+) = lift2 (+) >> (-) = lift2 (-) >> (*) = lift2 (*) >> abs = lift abs >> signum = lift signum >> fromInteger = Wrapped >> where >>lift2 f (Wrapped a)

Re: Local definitions in the class instances

2011-01-30 Thread John Meacham
On Thu, Jan 27, 2011 at 3:07 AM, Boris Lykah wrote: > I think it would be convenient to allow adding variables and > functions, which are not members of the class,  to a class instance so > that they are visible only in the instance scope. It will help if the > same functions are used by several c

Re: Local definitions in the class instances

2011-01-30 Thread Boris Lykah
Thanks for pointing at the problems with new and default class functions. But if we distinct the local and class functions I see no other problems. Iavor, your local/in suggestion is very interesting. I would like to see local declarations in the Haskell standard some day. However, it affects much

Re: Local definitions in the class instances

2011-01-27 Thread Nick Bowler
On 2011-01-27 13:07 +0200, Boris Lykah wrote: > I think it would be convenient to allow adding variables and > functions, which are not members of the class, to a class instance so > that they are visible only in the instance scope. It will help if the > same functions are used by several class fu

Re: Local definitions in the class instances

2011-01-27 Thread Iavor Diatchki
Hello, One issue I can see with such a change is that now it is not obvious which declarations define methods in the instance, and which are just helper functions. For example, currently, if I mistype the name of a method in a class (which happens often), the program is rejected because there is

Local definitions in the class instances

2011-01-27 Thread Boris Lykah
I think it would be convenient to allow adding variables and functions, which are not members of the class, to a class instance so that they are visible only in the instance scope. It will help if the same functions are used by several class functions. Example: When implementing Num class for my