diff --git a/app/MyGetOpt.hs b/app/MyGetOpt.hs index 6126c2e..42bb3ed 100644 --- a/app/MyGetOpt.hs +++ b/app/MyGetOpt.hs @@ -6,7 +6,7 @@ instance Functor Parser where -- fmap :: (a -> b) -> f a -> f b fmap f p = P $ \x -> case parse p x of Nothing -> Nothing - Just (y, lo) -> Just $ (f y, lo) + Just (y, lo) -> Just (f y, lo) instance Applicative Parser where -- pure :: a -> f a @@ -17,14 +17,20 @@ instance Applicative Parser where Nothing -> Nothing Just (y, lo) -> parse (fmap y p) lo +instance Monad Parser where + -- (>>=) :: forall a b. m a -> (a -> m b) -> m b + (>>=) p f = P $ \x -> case parse p x of + Nothing -> Nothing + Just (y, lo) -> parse (f y) lo + instance Alternative Parser where -- empty :: f a empty = P (\x -> Nothing) -- (<|>) :: f a -> f a -> f a - -- (<|>) a b = P $ \x -> case parse a x of - -- Nothing -> b - -- _ -> a + (<|>) a b = P $ \x -> case parse a x of + Nothing -> parse b x + y -> y data Configuration = Configuration { rule :: Int, @@ -40,4 +46,41 @@ defaultConfiguration = Configuration { Main.lines = Nothing, window = Just 80, move = Just 0 -} \ No newline at end of file +} + +-- +--data PeutEtre a = Juste a | Rien +-- +--instance Functor PeutEtre where +-- -- fmap :: (a -> b) -> f a -> f b +-- fmap _ Rien = Rien +-- fmap f (Juste x) = Juste $ f x +-- +--instance Applicative PeutEtre where +-- -- pure :: a -> f a +-- pure x = Juste x +-- +-- -- (<*>) :: f (a -> b) -> f a -> f b +-- (<*>) _ Rien = Rien +-- (<*>) Rien _ = Rien +-- (<*>) (Juste f) (Juste x) = Juste $ f x +-- +--instance Semigroup PeutEtre where +-- -- (<>) :: a -> a -> a +-- (<>) Rien x = x +-- (<>) x _ = x +-- (<>) Rien Rien = Rien +-- +--instance Monad PeutEtre where +-- -- (>>=) :: forall a b. m a -> (a -> m b) -> m b +-- (>>=) Rien _ = Rien +-- (>>=) (Juste x) f = f x +-- +--instance Alternative PeutEtre where +-- -- empty :: f a +-- empty = Rien +-- +-- -- (<|>) :: f a -> f a -> f a +-- (<|>) (Juste a) _ = Juste a +-- (<|>) _ (Juste a) = Juste a +-- (<|>) _ _ = Rien \ No newline at end of file