Andy Melnikov (nponeccop) wrote,
Andy Melnikov

Написал я было 2 функции:
everything :: (Enum a, Bounded a) => [a]
everything = enumFromTo minBound maxBound

everythingI :: (Bounded a, Ix a) => [a]
everythingI :: range (minBound, maxBound)
и понял, что нужных инстансов нет :(
instance Bounded a => Bounded (Maybe a) where
        minBound = Nothing
        maxBound = Just maxBound

instance Enum a => Enum (Maybe a) where
        toEnum 0 = Nothing
        toEnum x = Just $ toEnum $ x - 1
        fromEnum Nothing = 0
        fromEnum (Just x) = fromEnum x + 1
Проверяем, всё охуенно:
> everything :: [Maybe (Maybe Bool)]
[Nothing,Just Nothing,Just (Just False),Just (Just True)]
А вот и хуй!

Но направление игрищ оказалось плодотворным:
instance (Eq b, Enum a, Bounded a) => Eq (a -> b) where
        f == g = all (\x -> f x == g x) everything

instance (Bounded b) => Bounded (a -> b) where
        minBound = const minBound
        maxBound = const maxBound
Вот Enum (a -> b) написать бы!
Tags: все пидарасы а я

  • Post a new comment


    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.