TP | 21 Sep 12:29 2013
Picon

using "default" declaration for overloaded numeric operations

Hi,

I try to develop an embedded domain specific language in Haskell.
I don't want to type "::Rational" all the time, so I try to use a default 
declaration for my types.

This works correctly in this simple example:

------------------------------------------
default (Integer, Double) -- "default default"

mag :: Float -> Float -> Float
mag x y = sqrt( x^2 + y^2 )

main = do

print $ mag 1 1
------------------------------------------

Indeed we obtain sqrt(2) as a result. If we replace the default declaration 
by:
default ()
, we obtain errors at compilation as expected: the type of `2` is ambiguous.

Now let us consider a more complicated example:

------------------------------------------
{-# LANGUAGE FlexibleInstances #-}
import Prelude hiding ((^^))
import Data.Ratio
(Continue reading)


Gmane