[Haskell-beginners] Re: (Integral b, RealFrac b) to Int

han e at xtendo.org
Tue Feb 9 02:53:13 EST 2010


I made a mistake in copying the original code.

The correct version is:

line (sx, sy) (tx, ty)
	| abs (sx - tx) > abs (sy - ty) =
		zip xs [round (sy + (sy - ty) * x / xd) | x <- [0 .. xd]]
	| otherwise =
		zip [round (sx + (sx - tx) * y / yd) | y <- [0 .. yd]] ys
	where
		xs = target sx tx
		ys = target sy ty
		xd = abs (sx - tx)
		yd = abs (sy - ty)

On Tue, Feb 9, 2010 at 4:40 PM, han <e at xtendo.org> wrote:
> I have this code:
>
> line (sx, sy) (tx, ty)
>        | abs (sx - tx) > abs (sy - ty) =
>                zip xs [(sy + (sy - ty) * x / xd) | x <- [0 .. xd]]
>        | otherwise =
>                zip [(sx + (sx - tx) * y / yd) | y <- [0 .. yd]] ys
>        where
>                xs = target sx tx
>                ys = target sy ty
>                xd = abs (sx - tx)
>                yd = abs (sy - ty)
>
> It currently has the inferred type signature of
>
> (Integral b, RealFrac b) => (b, b) -> (b, b) -> [(b, b)]
>
> and I want it to be
>
> (Int, Int) -> (Int, Int) -> [(Int, Int)]
>
> which, when coerced, causes an error.
>
> Any idea?
>


More information about the Beginners mailing list