fork(1) download
  1. data Nested a
  2. = Value a
  3. | List [Nested a]
  4. deriving (Eq, Show)
  5.  
  6. nested :: Nested Int
  7. nested = [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;
Compilation error #stdin compilation error #stdout 0s 6220KB
stdin
Standard input is empty
compilation info
[1 of 1] Compiling Main             ( prog.hs, prog.o )

prog.hs:7:10:
    Couldn't match expected type `Nested Int'
                with actual type `[Nested Int]'
    In the expression: [nestedTwo, Value 1]
    In an equation for `nested': nested = [nestedTwo, Value 1]
stdout
Standard output is empty