Created
February 2, 2016 15:13
-
-
Save kseo/1c781c3c940ff855d569 to your computer and use it in GitHub Desktop.
An implementation of length function in terms of Const functor
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
import Prelude hiding (length) | |
newtype Const a b = Const a | |
unConst :: Const c a -> c | |
unConst (Const x) = x | |
length' :: [a] -> Const Int a | |
length' [] = Const 0 | |
length' (x:xs) = Const (1 + unConst (length' xs)) | |
length :: [a] -> Int | |
length xs = unConst (length' xs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment