Skip to content

Instantly share code, notes, and snippets.

@dskecse
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dskecse/08fb2ce90663a820abbf to your computer and use it in GitHub Desktop.
Save dskecse/08fb2ce90663a820abbf to your computer and use it in GitHub Desktop.
Implementations of math function in Haskell
-- | ln (abs(sin(x))), if x > 5
-- y = | x^2 + a^2, if x <= 5 and a <= 3
-- | x / a + 7.8*a, if x <= 5 and a > 3
y x a = if x > 5
then log (abs (sin (x)))
else
if x <= 5 && a <= 3
then x^2 + a^2
else x / a + 7.8 * a
y' x a = case x > 5 of
True -> log (abs (sin (x)))
False -> case x <= 5 && a <= 3 of
True -> x^2 + a^2
False -> x / a + 7.8 * a
-- guards
y'' x a | x > 5 = log (abs (sin (x)))
| x <= 5 && a <= 3 = x^2 + a^2
| otherwise = x / a + 7.8 * a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment