Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Control.Monad
- --1
- a = [Just 2, Just 3, Nothing]
- b = a++[Nothing]
- c = map (fmap (^2)) a
- --2
- d = Just [1, 2, 3]
- e = fmap (map (^2)) d
- --3
- f = ([1, 2, 3], Just 2)
- g = fmap (fmap(^2)) f
- --4
- h = [Left "Hello", Right 7, Right 3, Left "Oops"]
- i = map (fmap (^2)) h
- --5
- j = Right [1, 2, 3]
- k = fmap (map (^2)) j
- --6
- l :: ([Maybe Int], Either String Int)
- l = ([Just 2], Right 5)
- m = fmap (fmap(^2)) l
- --7
- n = [Left "hello", Right (Just 5), Right Nothing, Right (Just 8)]
- o = fmap (fmap(fmap(^2))) n
- --8 Опр-ть представителя класса типов функтор для сл.типа:
- data Point3d a = Point3d a a a deriving Show
- instance Functor Point3d where
- fmap f (Point3d x y z) = Point3d (f x) (f y) (f z)
- --9 Опр-ть представителя класса типов функтор для типа GeomPrimitive
- data GeomPrimitive a = Point (Point3d a) | LineSegment (Point3d a) (Point3d a) deriving Show
- instance Functor GeomPrimitive where
- fmap f (Point (Point3d x y z)) = Point (Point3d (f x) (f y) (f z))
- fmap f (LineSegment x y) = LineSegment (fmap f x) (fmap f y)
- --10
- ff = (\x -> map (2^) [0..x]) >=> (\x -> [0..x]) --первая и вторая стрелки Клейсли
- gg = \x -> map (2^) [0..x]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement