her.esy.fun/src/drafts/haskell-design-pattern-in-clojure/index.org
Yann Esposito (Yogsototh) 2b90505d7b
iTerm profile switch
2019-11-10 22:05:12 +01:00

843 B

Haskell Design Pattern in Clojure

TL;DR: Some clever Haskell trick can in fact be simulated quite efficiently with Clojure.

Monads

  fullName :: Maybe Text -> Maybe Text -> Maybe Text
  fullName firstName lastName = do
      x <- firstName
      y <- lastName
      result <- return (x <> y)

  ask :: IO (Maybe Text)
  ask = do
    l <- readLine
    return $ if null l then Nothing else Just l

  askName <- fullName <$> ask "What is your first name?"
                      <*> ask "What is your last name?"