summaryrefslogtreecommitdiff
path: root/testsuite/tests/mdo/should_compile/mdo002.hs
blob: 19e63bffc9e6dcd6b3724f203dcae55465290283 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
{-# OPTIONS -XRecursiveDo #-}

-- test of user defined instance of MonadFix

module Main (main) where

import Control.Monad
import Control.Monad.Fix

data X a = X a deriving Show

instance Functor X where
  fmap f (X a) = X (f a)

instance Applicative X where
  pure  = X
  (<*>) = ap

instance Monad X where
  (X a) >>= f = f a

instance MonadFix X where
  mfix f = fix (f . unX)
         where unX ~(X x) = x

z :: X [Int]
z = mdo x <- return (1:x)
        return (take 4 x)

main = print z