haskell-ja > Archives > 2011/12/22

2011/12/22 03:30:39 UTCshelarcy
#
以前話題になっていた Foreign.C.Types.CTime に対して Integral クラスのインスタンスを定義する方法 [http://chaton.practical-scheme.net/haskell-ja/a/2011/10/04 http://chaton.practical-scheme.net/haskell-ja/a/2011/10/26 ] ですが、無事 GHC 7.4.1 RC 1 では以下のような形で定義することができるようになりました。
#
{-# LANGUAGE GeneralizedNewtypeDeriving, StandaloneDeriving #-}
import Data.Int
import Foreign.C.Types

deriving instance Integral CTime
#
GHCi, version 7.4.0.20111219: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
[1 of 1] Compiling Main             ( C:\home\Test.hs, interpreted )
Ok, modules loaded: Main.
*Main> :i CTime
newtype CTime = CTime Int32     -- Defined in `Foreign.C.Types'
instance Integral CTime -- Defined at C:\home\Test.hs:5:1
instance Enum CTime -- Defined in `Foreign.C.Types'
instance Eq CTime -- Defined in `Foreign.C.Types'
instance Num CTime -- Defined in `Foreign.C.Types'
instance Ord CTime -- Defined in `Foreign.C.Types'
instance Read CTime -- Defined in `Foreign.C.Types'
instance Real CTime -- Defined in `Foreign.C.Types'
instance Show CTime -- Defined in `Foreign.C.Types'
2011/12/22 05:03:58 UTCkazu
#
おお、ついにですか!