[Haskell-beginners] Question on Real World Haskell ch.13 SymbolicManip

Brandon Allbery allbery.b at gmail.com
Wed Jun 1 03:14:40 CEST 2011

On Tue, May 31, 2011 at 20:48, Jake Penton <djp at arqux.com> wrote:
> Ok, so far so good. But the following example seems quite astounding to me:
> ghci> (5 * 10 + 2)::SymbolicManip Int
> Arith Plus (Arith Mul (Number 5) (Number 10)) (Number 2)
> The book says to notice that haskell "converted" 5 * 10 + 2 into a
> SymbolicManip. Indeed!
> My understanding breaks down at this point. I suspect that it may be my weak
> grasp of the implications of lazy evaluation, and typeclasses generally. My

It's not lazy evaluation; it's the combination of types and the
automatic translation of literal values to calls to fromLiteral per
the Haskell language definition.  Since in this case, the type
produced by fromLiteral must be a SymbolicManip Int for the entire
expression to work out to a SymbolicManip Int, each literal becomes
(Number whatever) and then the operators are taken from SymbolicManip
to preserve the type.

More information about the Beginners mailing list