Created
August 27, 2016 06:49
-
-
Save kika/b3dbba968f52614f71ac89d066723b21 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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