1module Main where
2
3import Prelude
4import Data.Eq (class Eq1)
5import Effect.Console (log)
6import Test.Assert
7
8type MyRecord a = { myField :: a }
9
10data M f a
11  = M0 a (Array a)
12  | M1 Int
13  | M2 (f a)
14  | M3 { foo :: Int, bar :: a, baz :: f a }
15  | M4 (MyRecord a)
16
17derive instance eqM :: (Eq1 f, Eq a) => Eq (M f a)
18derive instance functorM :: Functor f => Functor (M f)
19
20data T a = T (forall t. Show t => t -> a)
21derive instance functorT :: Functor T
22
23type MA = M Array
24
25main = do
26  assert $ map show (M0 0 [1, 2] :: MA Int) == M0 "0" ["1", "2"]
27  assert $ map show (M1 0 :: MA Int) == M1 0
28  assert $ map show (M2 [0, 1] :: MA Int) == M2 ["0", "1"]
29  assert $ map show (M3 {foo: 0, bar: 1, baz: [2, 3]} :: MA Int) == M3 {foo: 0, bar: "1", baz: ["2", "3"]}
30  assert $ map show (M4 { myField: 42 }) == (M4 { myField: "42" } :: MA String)
31
32  case map show (T \_ -> 42) of
33    T f -> assert $ f "hello" == "42"
34    _   -> assert false
35
36  log "Done"
37