Skip to content

Instantly share code, notes, and snippets.

@league
Created February 22, 2017 01:55
Show Gist options
  • Save league/07ea9764b8bc6c25d276b09934b69330 to your computer and use it in GitHub Desktop.
Save league/07ea9764b8bc6c25d276b09934b69330 to your computer and use it in GitHub Desktop.
{-# LANGUAGE FlexibleInstances #-}
lift2 op f g x = op (f x) (g x)
instance Num a => Num (a -> a) where
(+) = lift2 (+)
(*) = lift2 (*)
abs = (.) abs
signum = (.) signum
negate = (.) negate
fromInteger i _ = fromInteger i
instance Fractional a => Fractional (a -> a) where
(/) = lift2 (/)
fromRational r _ = fromRational r
{-
let t = sin / cos in map t [1,2,pi,4]
[1.557407724654902,-2.185039863261519,-1.2246467991473532e-16,1.1578212823495775]
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment