Skip to content

Instantly share code, notes, and snippets.

@chomado
Created February 24, 2014 19:47
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 chomado/9195593 to your computer and use it in GitHub Desktop.
Save chomado/9195593 to your computer and use it in GitHub Desktop.
{- –- 普通の再帰-- -}
my_mul :: Integer -> Integer -> Integer
my_mul m 1 = m
my_mul m n = my_mul m (n - 1) + m
{- –- 末尾再帰-- -}
my_mul_iter :: Integer -> Integer -> Integer
my_mul_iter x y = iter x y x
where
iter :: Integer -> Integer -> Integer -> Integer
iter _ 1 acc = acc
iter m n acc = iter m (n - 1) (acc + m)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment