blob: 216c792f3280bac8e6227507428bdf82b5e31cb5 (
plain)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
|
class NewFunctor f where
new_fmap :: (a -> b) -> f a -> f b
data N a = Z a | S (N a)
nmap f (Z x) = Z (f x)
nmap f (S n) = S (nmap f n)
tag (Z x) = x
tag (S n) = tag n
instance NewFunctor N where
new_fmap = nmap
--class Strange f where
-- zero :: a -> f a
-- suc :: f a -> f a
-- tag :: f a -> a
--class FMonad m where
-- (>>=) :: m a -> (a -> m b) -> m b
-- (>>) :: m a -> m b -> m b
-- return :: a -> m a
-- fail :: String -> m a
--
-- m >> k = m >>= \_ -> k
-- fail s = error s
--instance Strange N
-- where
-- zero x = Z x
-- suc y = S y
-- tag n = gettag n
twice :: NewFunctor f => (a -> a) -> f a -> f a
twice f x = new_fmap f (new_fmap f x)
main = putStr (tag (nmap (\x -> x) (Z "hello world\n")))
--main = putStr (tag (nmap (\x -> x) (Z "hello world\n")))
-- main = putStr (tag {- (twice (\x -> x) -} (Z "hello world\n"))
|