[Haskell-cafe] A type class puzzle

Tomasz Zielonka tomasz.zielonka at gmail.com
Tue Oct 31 16:35:07 EST 2006


On Tue, Oct 31, 2006 at 03:12:53PM +0200, Yitzchak Gale wrote:
> But I would rather not be forced to write things like
> 
> >replace (I 0 $ I 2 $ I 3 $ ())
> 
> in my code. My first attempt was very similar to yours,
> except I used
> 
> >replace (0, (2, (3, ())))
> 
> instead of your Index type.

I started with it too, but I had to disambiguate the numeric type, eg.
by saying: (0 :: Int, (2 :: Int, (3 :: Int, ()))). Hmmm... I could solve
it without creating a new type.

> I don't like my solution, either.
> 
> So I guess I would define a full solution as something
> nice enough to be used in practice. Let's be more
> concrete - it has to be nice enough that most people
> who need, say, replace2 or replace3, in real life, would
> actually use your function instead of writing it out by hand.

I think that in pracice I would still prefer the version with
indices gathered in a single argument - it is a bit more uniform,
more first-class, etc. Hmmm... Haskell's Arrays are a good example.

> Maybe others would disagree, but so far, I personally
> do not use either your solution or my solution. I write it
> out by hand.

Well, I didn't yet have a need for such a function...

> >If you insist that each index should be given as a separate
> >function argument, it may be possible to achieve it using the tricks
> >that allow to write the variadic composition operator.
> 
> I am not familiar with that. Do you have a reference?

I think it's in one of Oleg's articles mentioned in other replies.

> Is that the best way to do it? (Is that a way to do it at all?)

I am not sure.

Best regards
Tomasz


More information about the Haskell-Cafe mailing list