Created
December 10, 2016 01:19
-
-
Save naoto-ogawa/5b4f9447c063e1e489b0cf442d8ac220 to your computer and use it in GitHub Desktop.
fail function of monad
This file contains 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
-- fail function | |
> :t fail | |
fail :: Monad m => String -> m a | |
> :t (fail "failure") | |
(fail "failure") :: Monad m => m a | |
> fail "failure" | |
*** Exception: user error (failure) | |
> | |
> | |
-- Maybe fail ==> Nothing | |
> | |
> :t (fail "failure") :: Maybe Int | |
(fail "failure") :: Maybe Int :: Maybe Int | |
> (fail "failure") :: Maybe Int | |
Nothing | |
> :t (fail "failure") :: Maybe String | |
(fail "failure") :: Maybe String :: Maybe String | |
> (fail "failure") :: Maybe String | |
Nothing | |
> | |
-- List fail ==> [] | |
> | |
> :t (fail "failure") :: [Int] | |
(fail "failure") :: [Int] :: [Int] | |
> (fail "failure") :: [Int] | |
[] | |
> :t (fail "failure") :: [String] | |
(fail "failure") :: [String] :: [String] | |
> (fail "failure") :: [String] | |
[] | |
> | |
-- Either fail ==> Exception | |
> | |
> :t (fail "failure") :: Either Int String | |
(fail "failure") :: Either Int String :: Either Int String | |
> (fail "failure") :: Either Int String | |
*** Exception: failure | |
> :t (fail "failure") :: Either String Int | |
(fail "failure") :: Either String Int :: Either String Int | |
> (fail "failure") :: Either String Int | |
*** Exception: failure | |
> | |
-- Tuple fail ==> Exception | |
> | |
> :t (fail "failure") :: (String ,Int) | |
(fail "failure") :: (String ,Int) :: (String, Int) | |
> (fail "failure") :: (String ,Int) | |
*** Exception: failure | |
> :t (fail "failure") :: (Int, String) | |
-- (->) fail | |
> | |
> :t (fail "failure") :: Int -> String | |
(fail "failure") :: Int -> String :: Int -> String | |
> (fail "failure") :: Int -> String | |
<interactive>:139:1: error: | |
• No instance for (Show (Int -> String)) | |
arising from a use of ‘print’ | |
(maybe you haven't applied a function to enough arguments?) | |
• In a stmt of an interactive GHCi command: print it | |
> | |
> (fail "failure") :: String -> Int | |
<interactive>:141:1: error: | |
• No instance for (Show (String -> Int)) | |
arising from a use of ‘print’ | |
(maybe you haven't applied a function to enough arguments?) | |
• In a stmt of an interactive GHCi command: print it | |
> :t (fail "failure") :: String -> Int | |
(fail "failure") :: String -> Int :: String -> Int | |
> | |
> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment