Quick actions

cmd+k|ctrl+k

Navigation

Languages

Haskell Datatype

Snippet info

Language

Haskell

Visibility

public

Author

steinwaywhw

Created

2016-09-14T03:27:13Z

Updated

2016-09-14T03:27:13Z

data IList = INil
           | ICons Int IList
           deriving Show

list_len :: IList -> Int
list_len INil        = 0
list_len (ICons _ l) = 1 + list_len l

list_get :: IList -> Int -> Int
list_get (ICons d _) 0 = d
list_get (ICons _ l) n = list_get l (n - 1)

list_reverse :: IList -> IList 
list_reverse l = list_reverse_do l INil
    where list_reverse_do INil l = l
          list_reverse_do (ICons a l) b = list_reverse_do l (ICons a b)
          
main = print $ list_reverse $ ICons 10 (ICons 11 (ICons 12 INil))
INFO