Last active
June 8, 2017 21:45
-
-
Save nobsun/247b200c2394892c84f5f9688d8e18af to your computer and use it in GitHub Desktop.
多相関数を数える ref: http://qiita.com/nobsun/items/5662968f1c381695e7ff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
poly00 :: Maybe a -> Maybe a | |
poly00 = \ ma -> case ma of | |
Nothing -> Nothing | |
Just x -> Nothing | |
poly01 :: Maybe a -> Maybe a | |
poly01 = \ ma -> case ma of | |
Nothing -> Nothing | |
Just !x -> Nothing | |
poly02 :: Maybe a -> Maybe a | |
poly02 = \ ma -> case ma of | |
Nothing -> Nothing | |
Just x -> Just x | |
poly03 :: Maybe a -> Maybe a | |
poly03 = \ ma -> case ma of | |
Nothing -> Nothing | |
Just !x -> Just x | |
poly04 :: Maybe a -> Maybe a | |
poly04 = \ ma -> case ma of | |
Nothing -> Nothing | |
Just x -> Just undefined | |
poly05 :: Maybe a -> Maybe a | |
poly05 = \ ma -> case ma of | |
Nothing -> Nothing | |
Just !x -> Just undefined | |
poly06 :: Maybe a -> Maybe a | |
poly06 = \ ma -> case ma of | |
Nothing -> Nothing | |
Just x -> undefined | |
poly07 :: Maybe a -> Maybe a | |
poly07 = \ ma -> case ma of | |
Nothing -> Just undefined | |
Just x -> Nothing | |
poly08 :: Maybe a -> Maybe a | |
poly08 = \ ma -> case ma of | |
Nothing -> Just undefined | |
Just !x -> Nothing | |
poly09 :: Maybe a -> Maybe a | |
poly09 = \ ma -> case ma of | |
Nothing -> Just undefined | |
Just x -> Just x | |
poly10 :: Maybe a -> Maybe a | |
poly10 = \ ma -> case ma of | |
Nothing -> Just undefined | |
Just !x -> Just x | |
poly11 :: Maybe a -> Maybe a | |
poly11 = \ ma -> case ma of | |
Nothing -> Just undefined | |
Just x -> Just undefined | |
poly12 :: Maybe a -> Maybe a | |
poly12 = \ ma -> case ma of | |
Nothing -> Just undefined | |
Just !x -> Just undefined | |
poly13 :: Maybe a -> Maybe a | |
poly13 = \ ma -> case ma of | |
Nothing -> Just undefined | |
Just x -> undefined | |
poly14 :: Maybe a -> Maybe a | |
poly14 = \ ma -> case ma of | |
Nothing -> undefined | |
Just x -> Nothing | |
poly15 :: Maybe a -> Maybe a | |
poly15 = \ ma -> case ma of | |
Nothing -> undefined | |
Just !x -> Nothing | |
poly16 :: Maybe a -> Maybe a | |
poly16 = \ ma -> case ma of | |
Nothing -> undefined | |
Just x -> Just x | |
poly17 :: Maybe a -> Maybe a | |
poly17 = \ ma -> case ma of | |
Nothing -> undefined | |
Just !x -> Just x | |
poly18 :: Maybe a -> Maybe a | |
poly18 = \ ma -> case ma of | |
Nothing -> undefined | |
Just x -> Just undefined | |
poly19 :: Maybe a -> Maybe a | |
poly19 = \ ma -> case ma of | |
Nothing -> undefined | |
Just !x -> Just undefined | |
poly20 :: Maybe a -> Maybe a | |
poly20 = \ ma -> case ma of | |
Nothing -> undefined | |
Just x -> undefined | |
poly21 :: Maybe a -> Maybe a | |
poly21 = \ ma -> Nothing | |
poly22 :: Maybe a -> Maybe a | |
poly22 = \ ma -> Just undefined | |
poly23 :: Maybe a -> Maybe a | |
poly23 = \ ma -> Just $ case ma of { Just x -> x } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
printmaybe :: Show a => Maybe a -> IO () | |
printmaybe m = catch (case m of | |
Nothing -> putStrLn "Nothing" | |
Just x -> putStrLn . ("Just " ++) =<< showio x | |
) | |
(\ (e :: SomeException) -> putStrLn "⊥") | |
showio :: Show a => a -> IO String | |
showio a = catch (return $ show a) (\ (e :: SomeException) -> return "⊥") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{- ^ | |
>>> inputs :: [Maybe ()]; inputs = [Nothing, Just (), Just undefined, undefined] | |
>>> mapM_ (printmaybe . poly00) inputs | |
Nothing | |
Nothing | |
Nothing | |
⊥ | |
>>> mapM_ (printmaybe . poly01) inputs | |
Nothing | |
Nothing | |
⊥ | |
⊥ | |
>>> mapM_ (printmaybe . poly02) inputs | |
Nothing | |
Just () | |
Just ⊥ | |
⊥ | |
>>> mapM_ (printmaybe . poly03) inputs | |
Nothing | |
Just () | |
⊥ | |
⊥ | |
>>> mapM_ (printmaybe . poly04) inputs | |
Nothing | |
Just ⊥ | |
Just ⊥ | |
⊥ | |
>>> mapM_ (printmaybe . poly05) inputs | |
Nothing | |
Just ⊥ | |
⊥ | |
⊥ | |
>>> mapM_ (printmaybe . poly06) inputs | |
Nothing | |
⊥ | |
⊥ | |
⊥ | |
>>> mapM_ (printmaybe . poly07) inputs | |
Just ⊥ | |
Nothing | |
Nothing | |
⊥ | |
>>> mapM_ (printmaybe . poly08) inputs | |
Just ⊥ | |
Nothing | |
⊥ | |
⊥ | |
>>> mapM_ (printmaybe . poly09) inputs | |
Just ⊥ | |
Just () | |
Just ⊥ | |
⊥ | |
>>> mapM_ (printmaybe . poly10) inputs | |
Just ⊥ | |
Just () | |
⊥ | |
⊥ | |
>>> mapM_ (printmaybe . poly11) inputs | |
Just ⊥ | |
Just ⊥ | |
Just ⊥ | |
⊥ | |
>>> mapM_ (printmaybe . poly12) inputs | |
Just ⊥ | |
Just ⊥ | |
⊥ | |
⊥ | |
>>> mapM_ (printmaybe . poly13) inputs | |
Just ⊥ | |
⊥ | |
⊥ | |
⊥ | |
>>> mapM_ (printmaybe . poly14) inputs | |
⊥ | |
Nothing | |
Nothing | |
⊥ | |
>>> mapM_ (printmaybe . poly15) inputs | |
⊥ | |
Nothing | |
⊥ | |
⊥ | |
>>> mapM_ (printmaybe . poly16) inputs | |
⊥ | |
Just () | |
Just ⊥ | |
⊥ | |
>>> mapM_ (printmaybe . poly17) inputs | |
⊥ | |
Just () | |
⊥ | |
⊥ | |
>>> mapM_ (printmaybe . poly18) inputs | |
⊥ | |
Just ⊥ | |
Just ⊥ | |
⊥ | |
>>> mapM_ (printmaybe . poly19) inputs | |
⊥ | |
Just ⊥ | |
⊥ | |
⊥ | |
>>> mapM_ (printmaybe . poly20) inputs | |
⊥ | |
⊥ | |
⊥ | |
⊥ | |
>>> mapM_ (printmaybe . poly21) inputs | |
Nothing | |
Nothing | |
Nothing | |
Nothing | |
>>> mapM_ (printmaybe . poly22) inputs | |
Just ⊥ | |
Just ⊥ | |
Just ⊥ | |
Just ⊥ | |
>>> mapM_ (printmaybe . poly23) inputs | |
Just ⊥ | |
Just () | |
Just ⊥ | |
Just ⊥ | |
-} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment