Following with the Types
val generateRequestUri : (String, String, String) => String =
(host: String, resource: String, id: String) => host +"/"+ resource + "/" + id
->
generateRequestUri :: String -> String -> String -> String
generateRequestUri host resource id = host ++ "/" ++ resource ++ "/" ++ id
ADT - Product Type
case class Status(code: Int, statusMessage: String)
->
data Status = Status {
code :: Int,
statusMessage :: String
}
ADT - Sum Type
sealed trait Result
object Success extends Result
object Failed extends Result
->
data Result = Success | Failed
Pattern Matching
def check(r : Result) = r match {
case Failed => "Failed"
case Success => "Success"
}
->
r = Success
case r of
Success -> "Success"
Failed -> "Failed"
It`s a dependency ( Hackage and Stackage package repository) and bulid tool (Using Cabal)
stack update
stack new haskell-http
stack build
stack exec haskell-http-exe
1. Add new dependencies to
Network.HTTP.Simple and
Data.ByteString into Cabal File
http-conduit, bytestring
2. Add Language Extension: OverloadedStrings
2. Build the project
3. Run GHCI with the dependencies: stack exec ghci
Context input -> Context result inptu -> result
But we are inside Context
so what we need is... Anybody??
FUNCTOR!
fmap :: Functor f => (a -> b) -> f a -> f b
<=>
(<$>) :: Functor f => (a -> b) -> f a -> f b
DIY
Do
IT
Yourself
or
Keep calm and download from: superSimpleHttpHaskellCLI