[Haskell-cafe] A type class puzzle
Nicolas Frisby
nicolas.frisby at gmail.com
Tue Oct 31 14:26:34 EST 2006
See
Connor McBride's "Faking It: Simulating Dependent Types in Haskell"
http://citeseer.ist.psu.edu/mcbride01faking.html
It might help; your example makes me think of the "nthFirst" function.
If it's different, I'md wager the polyvariadic stuff and nthFirst can
be reconciled on some level.
Nick
On 10/31/06, Greg Buchholz <haskell at sleepingsquirrel.org> wrote:
> Yitzchak Gale wrote:
> > Tomasz Zielonka wrote:
> > >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?
> > Is that the best way to do it? (Is that a way to do it at all?)
>
> You might find these articles somewhat related...
>
> Functions with the variable number of (variously typed) arguments
> http://okmij.org/ftp/Haskell/types.html#polyvar-fn
>
> Deepest functor [was: fmap for lists of lists of lists of ...]
> http://okmij.org/ftp/Haskell/deepest-functor.lhs
>
> ...That first article is the strangest. I couldn't reconcile the fact
> that if our type signature specifies two arguments, we can pattern
> match on three arguments in the function definition. Compare the number
> of arguments in the first and second instances...
>
> > class BuildList a r | r-> a where
> > build' :: [a] -> a -> r
> >
> > instance BuildList a [a] where
> > build' l x = reverse$ x:l
> >
> > instance BuildList a r => BuildList a (a->r) where
> > build' l x y = build'(x:l) y
>
> ...if you try something like...
>
> foo :: [a] -> a -> r
> foo l x y = undefined
>
> ...you'll get an error message like...
>
> The equation(s) for `foo' have three arguments,
> but its type `[a] -> a -> r' has only two
>
>
> YMMV,
>
> Greg Buchholz
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
More information about the Haskell-Cafe
mailing list