Sha256: a4acc66c28524d8dd532451a8504648f2d24b293ed1d885f8d6b8943fb8d97de

Contents?: true

Size: 721 Bytes

Versions: 268

Compression:

Stored size: 721 Bytes

Contents

module LinkedList ( LinkedList
                  , fromList, toList, reverseLinkedList
                  , datum, next, isNil, nil, new) where

data LinkedList a = Nil
                  | Cons { datum :: a
                         , next :: LinkedList a }
  deriving (Eq, Show)

new :: a -> LinkedList a -> LinkedList a
new = Cons

nil :: LinkedList a
nil = Nil

fromList :: [a] -> LinkedList a
fromList = foldr Cons Nil

toList :: LinkedList a -> [a]
toList Nil = []
toList (Cons x xs) = x : toList xs

reverseLinkedList :: LinkedList a -> LinkedList a
reverseLinkedList = go Nil
  where go acc Nil = acc
        go acc (Cons x xs) = (go $! Cons x acc) xs

isNil :: LinkedList a -> Bool
isNil Nil = True
isNil _ = False

Version data entries

268 entries across 268 versions & 1 rubygems

Version Path
trackler-2.2.1.159 tracks/haskell/exercises/simple-linked-list/examples/success-standard/src/LinkedList.hs
trackler-2.2.1.158 tracks/haskell/exercises/simple-linked-list/examples/success-standard/src/LinkedList.hs
trackler-2.2.1.157 tracks/haskell/exercises/simple-linked-list/examples/success-standard/src/LinkedList.hs
trackler-2.2.1.156 tracks/haskell/exercises/simple-linked-list/examples/success-standard/src/LinkedList.hs
trackler-2.2.1.155 tracks/haskell/exercises/simple-linked-list/examples/success-standard/src/LinkedList.hs
trackler-2.2.1.154 tracks/haskell/exercises/simple-linked-list/examples/success-standard/src/LinkedList.hs
trackler-2.2.1.153 tracks/haskell/exercises/simple-linked-list/examples/success-standard/src/LinkedList.hs
trackler-2.2.1.152 tracks/haskell/exercises/simple-linked-list/examples/success-standard/src/LinkedList.hs
trackler-2.2.1.151 tracks/haskell/exercises/simple-linked-list/examples/success-standard/src/LinkedList.hs
trackler-2.2.1.150 tracks/haskell/exercises/simple-linked-list/examples/success-standard/src/LinkedList.hs
trackler-2.2.1.149 tracks/haskell/exercises/simple-linked-list/examples/success-standard/src/LinkedList.hs
trackler-2.2.1.148 tracks/haskell/exercises/simple-linked-list/examples/success-standard/src/LinkedList.hs
trackler-2.2.1.147 tracks/haskell/exercises/simple-linked-list/examples/success-standard/src/LinkedList.hs
trackler-2.2.1.146 tracks/haskell/exercises/simple-linked-list/examples/success-standard/src/LinkedList.hs
trackler-2.2.1.145 tracks/haskell/exercises/simple-linked-list/examples/success-standard/src/LinkedList.hs
trackler-2.2.1.144 tracks/haskell/exercises/simple-linked-list/examples/success-standard/src/LinkedList.hs
trackler-2.2.1.143 tracks/haskell/exercises/simple-linked-list/examples/success-standard/src/LinkedList.hs
trackler-2.2.1.142 tracks/haskell/exercises/simple-linked-list/examples/success-standard/src/LinkedList.hs
trackler-2.2.1.141 tracks/haskell/exercises/simple-linked-list/examples/success-standard/src/LinkedList.hs
trackler-2.2.1.140 tracks/haskell/exercises/simple-linked-list/examples/success-standard/src/LinkedList.hs