エンジニアのソフトウェア的愛情

または私は如何にして心配するのを止めてプログラムを・愛する・ようになったか

リハビリ(中略)lis.hsに書き直してみた、のつづき

さらに昨日のつづき。


AtomShowインスタンスにしてみました。これでshow関数が使えるようになりました。
ふだんは手っ取り早く「data Atom (中略) deriving Show」とやって終りにしていたので、改めてHaskellの基本を調べなおして書き直し。基礎練習、大事ですね。


当該コードの抜粋。
こちら更新してます:gist:775233 · GitHub

instance Show Atom where
  show (INT i)         = show i
  show (REAL r)        = show r
  show (BOOL b)        = show b
  show (SYMBOL s)      = s
  show (LIST xs)       = (foldl (\s x -> s ++ ' ':show x) "(" xs) ++ " )"
  show (PROC args exp) = "proc " ++ (show args) ++ " " ++ (show exp)
  show (FUNCTION _)    = "function"