Last active
August 9, 2018 10:50
-
-
Save LucianU/1be522cba081617e3a37813bdd754812 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
fromIndex :: Int -> [a] -> Maybe a | |
fromIndex 0 (x:xs) = | |
Just x | |
fromIndex index [] = | |
Nothing | |
fromIndex index (x:xs) = | |
fromIndex (index - 1) xs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
[x]
special case. (This doesn't work as a base case, since[]
is not caught. Use[]
instead.)fromIndex'
is only necessary to keep track ofcurrIndex
, but you could useindex
recursively and subtract from it.