[Haskell-cafe] Variable-arity zipWith (re)invented.

adam vogt vogt.adam at gmail.com
Tue Dec 11 16:25:57 CET 2012


On Mon, Dec 10, 2012 at 7:23 PM, Takayuki Muranushi <muranushi at gmail.com> wrote:
> Repeated thanks to you, Adam! Your code is brilliantly simple.
>
> Sadly, I cannot reproduce the behaviors in your comments on my ghci
> (7.6.1)  .....
> Can we guess why? The version of packages we are using?
>
> Mines are here.
>
> https://github.com/nushio3/practice/tree/master/variable-arity/adam
>
>
>>>>  :t forZ [1,2,3] (+)
> forZ [1,2,3] (+)
>   :: (Num t, Num a, TypeCast br HFalse,
>       HBuild2' br (HCons [t] HNil) (a -> a -> a) r) =>
>      r
>>>>  forZ [1,2,3] [10] (+)
>
> <interactive>:13:1:
>     Couldn't match type `[y]' with `(a0 -> a0 -> a0) -> t0'
>     When using functional dependencies to combine
>       Apply ApplyZap (a, b) [y],
>         arising from the dependency `f a -> r'
>         in the instance declaration at Part1.lhs:193:12
>       Apply ApplyZap ([[t2]], [t1]) ((a0 -> a0 -> a0) -> t0),
>         arising from a use of `forZ' at <interactive>:13:1-4
>     In the expression: forZ [1, 2, 3] [10] (+)
>     In an equation for `it': it = forZ [1, 2, 3] [10] (+)
>>>> forZ [1,2,3] "hi there" (,)
>
> <interactive>:14:1:
>     Couldn't match type `[y]' with `(a0 -> b0 -> (a0, b0)) -> t0'
>     When using functional dependencies to combine
>       Apply ApplyZap (a, b) [y],
>         arising from the dependency `f a -> r'
>         in the instance declaration at Part1.lhs:193:12
>       Apply ApplyZap ([[Char]], [t1]) ((a0 -> b0 -> (a0, b0)) -> t0),
>         arising from a use of `forZ' at <interactive>:14:1-4
>     In the expression: forZ [1, 2, 3] "hi there" (,)
>     In an equation for `it': it = forZ [1, 2, 3] "hi there" (,)
>
>
>
> Best,
>
> Takayuki

Hi  Takayuki

I must have changed the imports at some point: the file doesn't work
here with the same HList and ghc versions either. It does work if I
change the `import Data.HList.FakePrelude' to `import
Data.HList.TypeCastGeneric2'.

Finally another note is that it only simplifies the type for the first
argument probably because of the hTrue in the definition of forZ:

*P4> :t \x -> forZ [1,2,3] x (+)
\x -> forZ [1,2,3] x (+)
  :: (Num a, Num t1,
      HBuild2' br (HCons [t1] HNil) b ((a -> a -> a) -> t),
      IsZip b br) =>
     b -> t
*P4> :t \x -> forZ x [1,2,3] (+)
\x -> forZ x [1,2,3] (+) :: Num x => [x] -> [x]

Adam



More information about the Haskell-Cafe mailing list