[Haskell-beginners] Calling "zipWith" using "^" function.
yi lu
zhiwudazhanjiangshi at gmail.com
Mon Nov 9 04:28:14 UTC 2015
Prelude> :t (**)
(**) :: Floating a => a -> a -> a
On Mon, Nov 9, 2015 at 12:14 PM, Venu Chakravorty <c.venu at aol.com> wrote:
> Hello there,
> This is just some toy program I was trying. I fail to understand why this
> works:
>
> =============================
> Prelude> zipWith (\ x y -> ((x ^ y) / (product [1..x]))) [1..3] [2,2,2]
> [1.0,2.0,1.5]
> =============================
>
> and this does not:
>
> =============================
> Prelude> zipWith (\ x y -> ((y ^ x) / (product [1..x]))) [1..3] [2,2,2]
>
> <interactive>:1:19:
> Ambiguous type variable `a' in the constraints:
> `Fractional a' arising from a use of `/' at <interactive>:1:19-44
> `Integral a' arising from a use of `^' at <interactive>:1:20-24
> Probable fix: add a type signature that fixes these type variable(s)
> ============================
> Note that the "^" function has "x" and "y" flipped.
>
> :t (^) says:
> ============================
> (^) :: (Num a, Integral b) => a -> b -> a
> ============================
>
> Could somebody please throw some light?
>
> Thanks.
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20151109/b87a6ef1/attachment-0001.html>
More information about the Beginners
mailing list