LINUX.ORG.RU

История изменений

Исправление Odalist, (текущая версия) :

Лучше Haskell пока ничего нету...

{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}
{-# LANGUAGE DeriveGeneric #-}
import Test.SmallCheck.Series
import GHC.Generics

data Tree a = Null | Fork (Tree a) a (Tree a)
    deriving Generic
instance Serial m a => Serial m (Tree a)
{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}
import Test.SmallCheck
import Test.SmallCheck.Series

newtype Light a = Light a

instance Serial m a => Serial m (Light a) where
  series = newtypeCons Light

data Tree a = Null | Fork (Tree a) a (Tree a)

instance Serial m a => Serial m (Tree a) where
  series = cons0 Null \/ cons3 Fork

instance CoSerial m a => CoSerial m (Tree a) where
  coseries rs =
    alts0 rs >>- \z ->
    alts3 rs >>- \f ->
    return $ \t ->
      case t of
        Null -> z
        Fork t1 x t2 -> f t1 x t2
  
instance CoSerial m a => CoSerial m (Light a) where
  coseries rs =
    newtypeAlts rs >>- \f ->
    return $ \l ->
      case l of
Light x -> f x

Исходная версия Odalist, :

Лучше Haskell пока ничего нету...

{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}
{-# LANGUAGE DeriveGeneric #-}
import Test.SmallCheck.Series
import GHC.Generics

data Tree a = Null | Fork (Tree a) a (Tree a)
    deriving Generic
instance Serial m a => Serial m (Tree a)