-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPipe.hs
More file actions
31 lines (23 loc) · 705 Bytes
/
Pipe.hs
File metadata and controls
31 lines (23 loc) · 705 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE UndecidableInstances #-}
class Pipe a b c d | a b c -> d, a b d -> c, a c d -> b, b c d -> a where
(<|) :: (a -> b) -> c -> d
instance Pipe a b a b where
(<|) = id
instance (Pipe a b c d, Functor f) => Pipe a b (f c) (f d) where
(<|) = fmap . (<|)
showInt :: Int -> String
showInt = show
testList :: [[Int]] -> [[String]]
testList = (showInt <|)
testFunc :: Int -> Int -> String
testFunc = showInt <| (+)
testApp :: String
testApp = showInt <| (1 :: Int)
main :: IO ()
main = do
print $ testList [[1, 2], [3, 4]]
print $ testFunc 1 2
print $ testApp