Skip to content

Instantly share code, notes, and snippets.

@cympfh
Last active December 21, 2015 10:29
Show Gist options
  • Save cympfh/6292199 to your computer and use it in GitHub Desktop.
Save cympfh/6292199 to your computer and use it in GitHub Desktop.
{-# LANGUAGE FlexibleInstances #-}
-- iota of SRFI-1
iota1 n = [0 .. n-1]
iota2 n m = [m .. m+n-1]
iota3 n m s = [m, m+s .. m+s*(n-1)]
class PType t where
iota :: t
instance PType (Int -> [Int]) where
iota = iota1
instance PType (Int -> Int -> [Int]) where
iota = iota2
instance PType (Int -> Int -> Int -> [Int]) where
iota = iota3
main = do
print $ (iota (3 :: Int) :: [Int])
print $ (iota (3 :: Int) (10 :: Int) :: [Int])
print $ (iota (3 :: Int) (10 :: Int) (-2 :: Int) :: [Int])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment