-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtil.hs
65 lines (54 loc) · 1.34 KB
/
Util.hs
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
module Util
( assert
, assertM
, esp
, eesp
, fesp
, eeesp
, feesp
, sp
, msp
, fromLeftReal
, mappily
, mcompose
) where
import Control.Exception.Base
import Data.Either
import Data.Text (unpack)
import Data.Text.Lazy (toStrict)
import System.IO.Unsafe
import Text.Pretty.Simple (pShow, pShowNoColor)
esp a = unsafePerformIO $ do
putStrLn $ show $ a
return a
eesp s a = unsafePerformIO $ do
putStrLn $ show $ s
return a
fesp f a = unsafePerformIO $ do
putStrLn $ show $ f a
return a
eeesp s a = unsafePerformIO $ do
putStrLn $ show $ (s, a)
return a
-- Fake ones for quickly disabling
feesp s a = a
sp x = unpack $ toStrict $ pShowNoColor $ x
msp x = putStrLn $ sp x
-- Really surprised this doesn't exist
fromLeftReal (Left a) = a
assertM :: Show b => b -> Bool -> a -> a
assertM m b a
| b = a
| otherwise = unsafePerformIO $ do
putStrLn $ show m
return $ assert b a
--return a
-- I am giving this a terrible name because I know it must exist but I don't
-- know enough to know what it's called and I refused to accept at the moment
-- that it might be called fmap.
mappily :: (a -> b) -> Maybe a -> Maybe b
mappily f (Just x) = Just (f x)
mappily f Nothing = Nothing
mcompose :: (b -> Maybe c) -> (a -> Maybe b) -> (a -> Maybe c)
mcompose f g x = case g x of Just y -> f y
Nothing -> Nothing