Skip to content

Instantly share code, notes, and snippets.

@tarquin-the-brave
Created May 12, 2020 12:14
Show Gist options
  • Save tarquin-the-brave/dd63e32bd371555b8c73cee41d90d11c to your computer and use it in GitHub Desktop.
Save tarquin-the-brave/dd63e32bd371555b8c73cee41d90d11c to your computer and use it in GitHub Desktop.
module Lib
( tot_1
, tot_2
) where
f :: Integral a => a -> a
f x = x `div` 3 - 2
tot_1 :: Integral a => [a] -> a
tot_1 = tot f
g :: Integral a => a -> a
g x
| f x >= 0 = f x + g(f x)
| otherwise = 0
tot_2 :: Integral a => [a] -> a
tot_2 = tot g
tot :: Integral a => (a -> a) -> [a] -> a
tot f = sum . fmap f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment