[Haskell-cafe] Numerics and Warnings

Tom Ellis tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk
Wed Apr 10 19:34:36 CEST 2013


On Wed, Apr 10, 2013 at 03:38:35PM +0100, Barak A. Pearlmutter wrote:
> In fiddling around with some numeric code in Haskell, I noticed some
> issues.  Basically, you get warnings if you write
> 
>   energy mass = mass * c^2
> 
> but not if you write
> 
>   energy mass = mass * c * c

Numeric typeclasses are syntactically convenient, but are rather too
implicit for my taste.  I prefer using monomorphic versions once the code
becomes serious.  For example,

import Prelude hiding ((^))
import qualified Prelude

(^) :: Num a => a -> Integer -> a
(^) = (Prelude.^)

energy mass = mass * c^2

This does not solve your other issues though.

Tom



More information about the Haskell-Cafe mailing list