fork download
  1. data Foo = Foo { bar :: String, baz :: Int }
  2.  
  3. main :: IO ()
  4. main = do
  5. putStrLn $ fooToString exampleFoo
  6. putStrLn $ safeFooToString exampleFoo
  7.  
  8. fooToString :: Foo -> String
  9. fooToString foo =
  10. case foo of
  11. Foo { bar = bar } ->
  12. bar
  13.  
  14. safeFooToString :: Foo -> String
  15. safeFooToString foo =
  16. case foo of
  17. Foo bar ->
  18. bar
  19.  
  20. exampleFoo :: Foo
  21. exampleFoo =
  22. Foo
  23. { bar = "Bar"
  24. , baz = 25
  25. }
Compilation error #stdin compilation error #stdout 0s 4500KB
stdin
Standard input is empty
compilation info
[1 of 1] Compiling Main             ( prog.hs, prog.o )

prog.hs:17:17: error:
    • The constructor ‘Foo’ should have 2 arguments, but has been given 1
    • In the pattern: Foo bar
      In a case alternative: Foo bar -> bar
      In the expression: case foo of { Foo bar -> bar }
   |
17 |                 Foo bar ->
   |                 ^^^^^^^
stdout
Standard output is empty