関数型プログラミング言語Haskell Part19
■ このスレッドは過去ログ倉庫に格納されています
0838デフォルトの名無しさん
2012/09/21(金) 16:43:10.99ただまあ832の例は関数従属と多引数型クラスでも複雑にはならない
{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, FunctionalDependencies #-}
module Mult where
import Prelude hiding (filter)
import qualified Prelude as P
import qualified Data.List as L
class FilterContext a b | b -> a where
filter :: (a -> Bool) -> [a] -> b
instance FilterContext a [a] where
filter = P.filter
instance FilterContext a ([a], [a]) where
filter = L.partition
*> filter (> 5) [1..10] :: [Int]
[6,7,8,9,10]
*> filter (> 5) [1..10] :: ([Int], [Int])
([6,7,8,9,10],[1,2,3,4,5])
■ このスレッドは過去ログ倉庫に格納されています