050: contextorder1b.hs

↑up

概要

049 の少し複雑なバージョン。

data A = A1 | A2 | A3
data B = B1 | B2

class MyShow a where
  myshow :: a -> [Char]

instance MyShow A where
  myshow A1 = "A1"
  myshow A2 = "A2"
  myshow A3 = "A3"

instance MyShow B where
  myshow B1 = "B1"
  myshow B2 = "B2"

data Pair a b = Pair a b

instance (MyShow a, MyShow b) => MyShow (Pair a b) where
  myshow (Pair x y) = "Pair " ++ myshow x ++ " " ++ myshow y

main = putStrLn $ myshow (Pair A1 B2)

調査ログ

2020-12-17 (Thu)

bunny 0.9.0 で試してみる。testrun の結果:

$ bunny testrun contextorder1b.hs 
/home/unno/bunny/0.9.0/bin/bunnyc -d ./jout/contextorder1b --xno-implicit-prelude /home/unno/bunny/0.9.0/lib/Prelude.hs
/home/unno/bunny/0.9.0/bin/bunnyc -d ./jout/contextorder1b --xlibrary-path /home/unno/bunny/0.9.0/lib contextorder1b.hs
Pair A1 B2

これは runhaskell での結果と同じで期待通り。

2021-10-24 (Sun)

全件確認の一環:

$ cat contextorder1b.hs 
data A = A1 | A2 | A3
data B = B1 | B2

class MyShow a where
  myshow :: a -> [Char]

instance MyShow A where
  myshow A1 = "A1"
  myshow A2 = "A2"
  myshow A3 = "A3"

instance MyShow B where
  myshow B1 = "B1"
  myshow B2 = "B2"

data Pair a b = Pair a b

instance (MyShow a, MyShow b) => MyShow (Pair a b) where
  myshow (Pair x y) = "Pair " ++ myshow x ++ " " ++ myshow y

main = putStrLn $ myshow (Pair A1 B2)
unno@unno-FMVD70GN7G ~/work/bissues/050 
$ runhaskell contextorder1b.hs 
Pair A1 B2
unno@unno-FMVD70GN7G ~/work/bissues/050 
$ ~/prj/bunny/compiler/bin/bunny testrun contextorder1b.hs 
/home/unno/prj/bunny/compiler/bin/bunnyc -d ./jout/contextorder1b --xno-implicit-prelude /home/unno/prj/bunny/compiler/bin/../lib/Prelude.hs
/home/unno/prj/bunny/compiler/bin/bunnyc -d ./jout/contextorder1b --xlibrary-path /home/unno/prj/bunny/compiler/bin/../lib contextorder1b.hs
Pair A1 B2