fork download
  1. data Nested a
  2. = Value a
  3. | List [Nested a]
  4. deriving (Eq, Show)
  5.  
  6. nested :: Nested Int
  7. nested = List [nestedTwo, Value 1]
  8. nestedTwo = List [nested, Value 2]
  9.  
  10. (!) :: Nested a -> Int -> Nested a
  11. (!) (Value _) _ = undefined
  12. (!) (List xs) n = xs !! n
  13.  
  14. main = do
  15. print $ nestedTwo ! 1;
  16. print $ nestedTwo ! 0 ! 1;
  17. print $ nestedTwo ! 0 ! 0 ! 1;
Success #stdin #stdout 0s 6220KB
stdin
Standard input is empty
stdout
Value 2
Value 1
Value 2