Skip to content

Instantly share code, notes, and snippets.

@kika
Created August 27, 2016 06:49
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 kika/b3dbba968f52614f71ac89d066723b21 to your computer and use it in GitHub Desktop.
Save kika/b3dbba968f52614f71ac89d066723b21 to your computer and use it in GitHub Desktop.
module TCO where
import Prelude
import Data.Either
import Control.Monad.Rec.Class
isEven::Int -> Boolean
isEven = tailRec (either isEven' isOdd') <<< Left
isOdd::Int -> Boolean
isOdd = tailRec (either isEven' isOdd') <<< Right
isEven' 0 = Right true
isEven' n = Left (Right (n - 1))
isOdd' 0 = Right false
isOdd' n = Left (Left (n - 1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment