[Solved] Haskell Data Types


By using ghci and simply inputing the code snippets you will see which of the values are accepted:

Prelude> data Bin = B Bin | C [ Int]
Prelude> a = C [ ]
Prelude> b = B ( B C [ 2])

<interactive>:3:9: error:
    • Couldn't match expected type ‘[Integer] -> Bin’
                  with actual type ‘Bin’
    • The function ‘B’ is applied to two arguments,
      but its type ‘Bin -> Bin’ has only one
      In the first argument of ‘B’, namely ‘(B C [2])’
      In the expression: B (B C [2])

<interactive>:3:11: error:
    • Couldn't match expected type ‘Bin’
                  with actual type ‘[Int] -> Bin’
    • Probable cause: ‘C’ is applied to too few arguments
      In the first argument of ‘B’, namely ‘C’
      In the first argument of ‘B’, namely ‘(B C [2])’
      In the expression: B (B C [2])
Prelude> c = B ( C [ 1..5])
Prelude> d = B (B (B (C[2,3])))

1

solved Haskell Data Types