Skip to content

Instantly share code, notes, and snippets.

@naoto-ogawa
Created December 10, 2016 01:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naoto-ogawa/5b4f9447c063e1e489b0cf442d8ac220 to your computer and use it in GitHub Desktop.
Save naoto-ogawa/5b4f9447c063e1e489b0cf442d8ac220 to your computer and use it in GitHub Desktop.
fail function of monad
-- 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