New paste Repaste Download
data Coin = Fair | Unfair deriving Show
data Face = Head | Tail deriving Eq
toss :: Coin -> [Face]
toss Fair = [Head, Tail]
toss Unfair = [Head, Head]
coins :: [Coin]
coins = [Fair, Unfair]
foo :: [(Coin, Face)]
foo = do
  coin <- coins         -- select a coin
  face <- toss coin     -- toss it
  cf <- (coin, face)    -- Error: * Couldn't match type `(,) Coin' with `[]'
  return cf
{-
MonadNonDeterminism.hs:44:9: error: [GHC-83865]
    * Couldn't match type `(,) Coin' with `[]'
      Expected: [Face]
        Actual: (Coin, Face)
    * In a stmt of a 'do' block: cf <- (coin, face)
      In the expression:
        do coin <- coins
           face <- toss coin
           cf <- (coin, face)
           return cf
      In an equation for `experiment2':
          experiment2
            = do coin <- coins
                 face <- toss coin
                 cf <- (coin, face)
                 ....
   |
44 |   cf <- (coin, face)
   |         ^^^^^^^^^^^^
MonadNonDeterminism.hs:46:10: error: [GHC-83865]
    * Couldn't match expected type `(Coin, Face)'
                  with actual type `Face'
    * In the first argument of `return', namely `cf'
      In a stmt of a 'do' block: return cf
      In the expression:
        do coin <- coins
           face <- toss coin
           cf <- (coin, face)
           return cf
   |
46 |   return cf
   |          ^^
-}
Filename: None. Size: 1kb. View raw, , hex, or download this file.

This paste expires on 2024-11-16 07:00:16.951575. Pasted through web.