Skip to content

Instantly share code, notes, and snippets.

@sharkdp
Created May 16, 2016 08:51
Show Gist options
  • Save sharkdp/cef1f5e2eddd1125176d08daa03ef45a to your computer and use it in GitHub Desktop.
Save sharkdp/cef1f5e2eddd1125176d08daa03ef45a to your computer and use it in GitHub Desktop.
module Main where
import Prelude
import Control.Monad.Eff.Console
import Data.Int as I
import Data.Complex as C
import Math as M
class Ring r <= Absolute r where
abs :: r -> Number
instance absoluteNumber :: Absolute Number where
abs = M.abs
instance absoluteInt :: Absolute Int where
abs = M.abs <<< I.toNumber
instance absoluteComplex :: Absolute C.Complex where
abs = C.magnitude
main = do
print $ abs (-2.3)
print $ abs (-3)
print $ abs (C.outCartesian (C.Cartesian 3.0 4.0))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment