Re: [Haskell-cafe] an instance in other than the last type parameters

2009-07-17 Thread Geoffrey Marchant
 data X a b = X a b instance Functor (X a) where
   fmap f (X a b) = X a (f b)

Yeah, that works just fine.



On Fri, Jul 17, 2009 at 1:14 PM, Petr Pudlak d...@pudlak.name wrote:

 Hi, I have probably a very simple question, but I wasn't able to figure it
 out
 myself.

 Consider a two-parameter data type:

  data X a b = X a b

 If I want to make it a functor in the last type variable (b), I can just
 define

  instance Functor (X a) where
fmap f (X a b) = X a (f b)

 But how do I write it if I want X to be a functor in its first type
 variable?
 Is that possible at all?
 Something like:

  instance Functor ??? where
  fmap f (X a b) = X (f a) b

 Thanks in advance,
  Petr
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Monoid wants a (++) equivalent

2009-07-01 Thread Geoffrey Marchant
Obviously `mappend` is good enough as it is.

Choosing (+) or () are just for prettifying code.

Generalizing (++) not only makes the code prettier, but also brings Monoid
into the Prelude.

You can either Do It Right(tm), or be conservative and try to maintain
backwards compatibility as much as possible.

I suspect most people in the community understand the trade-offs here, and
would agree on the proper solution. If that means rewriting the standard,
then so be it.


On Wed, Jul 1, 2009 at 12:26 PM, Ross Paterson r...@soi.city.ac.uk wrote:

 On Wed, Jul 01, 2009 at 10:55:39AM -0700, Bryan O'Sullivan wrote:
  Okay, here's a tentative plan that will help to figure out the answer.
 I'll
  build a fiddled base package that rewires the Monoid class to have (++)
 be the
  binary operator, and mappend as a synonym for it. I'll import the Monoid
 (++)
  into the Prelude. I'll see how much breaks. If that much builds smoothly,
 I'll
  see how much of the rest of Hackage builds, both with and without this
 custom
  base package. I'll follow up here with the results, along with a
 suggestion of
  how acceptable I think the observed level of breakage is.

 Generalizing (++) will break some Haskell 98 code, e.g.

  append = (++)

 I think that's a show-stopper.
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] List spine traversal

2009-06-29 Thread Geoffrey Marchant
I think I can see the point of forcing a list without forcing the actual
data, but is there a way to do this that works on circular lists as well?

On Mon, Jun 29, 2009 at 3:30 AM, Ketil Malde ke...@malde.org wrote:

 Deniz Dogan deniz.a.m.do...@gmail.com writes:

  What is the spine of a list? Google seems to fail me on this one.

 A (single-linked) list can be seen as a set of cons cells, where each
 cell contains two pointers, one to the next cons cell, and one to the
 cell's data contents ('car' and 'cdr' in Lisp parlance).

 The spine of the list is the cons cells and the next pointers, that
 is, the structure of the list, but not the actual data contained in
 it.

 -k
 --
 If I haven't seen further, it is by standing in the footprints of giants
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] A small puzzle: inTwain as function of foldr

2009-06-04 Thread Geoffrey Marchant
The linked paper appears to show the right style.
This appears to satisfy the conditions, however:

inTwain as = let (x,y,_) = foldr (\a (r,s,t) - case (t) of {b:(b':bs) -
(r,a:s,bs); _ - (a:r,s,t)}) ([],[],as) as in (x,y)

In the case of a list of odd length, the first half is given the extra
element.


On Thu, Jun 4, 2009 at 8:22 AM, Martijn van Steenbergen 
mart...@van.steenbergen.nl wrote:

 Bonjour café,

 A small puzzle:

 Consider the function inTwain that splits a list of even length evenly into
 two sublists:

  inTwain Hello world!
 (Hello ,world!)

 Is it possible to implement inTwain such that the recursion is done by one
 of the standard list folds?

 Is there a general way to tell if a problem can be expressed as a fold?

 Thank you,

 Martijn.
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe