Skip to content

Instantly share code, notes, and snippets.

@chomado
Last active August 29, 2015 13:56
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/9195381 to your computer and use it in GitHub Desktop.
Save chomado/9195381 to your computer and use it in GitHub Desktop.
{- –- 普通の再帰-- -}
my_soap :: Integer -> Integer
my_soap 0 = 0
my_soap n = my_soap (n-1) + n
{- –- 末尾再帰-- -}
my_soap_iter :: Integer -> Integer
my_soap_iter x = my_soap_iter2 x 0
my_soap_iter2 :: Integer -> Integer -> Integer
my_soap_iter2 0 acc = acc
my_soap_iter2 n acc = my_soap_iter2 (n-1) (acc + n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment