readFile :: String -> IO String
main = do
putStr "Please enter your name: "
name <- getLine
putStrLn ("'" ++ name ++ "'? That's a nice name!")
putStrLn ("It has " ++ length name ++ " characters.")
module Main where
import Prelude
import Control.Monad.Eff.Console (log)
greet :: String -> String
greet name = "Hello, " ++ name ++ "!"
main = log (greet "World")
log :: String -> Eff _ Unit
function log(message) {
return function() {
console.log(message)
return {}
}
}
httpGet :: URL -> Eff _ HttpResponse
httpGet :: URL
-> (HttpResponse -> Eff _ Unit)
-> Eff _ Unit
main =
getFirstArgument (\inputFile -> do
log ("Reading: " ++ inputFile)
readFile inputFile (\json ->
case parseJson json of
Left err ->
throw err
Right data ->
httpPost (url data) (payload data) (\resp ->
log resp.body)))
main = do
inputFile <- getFirstArgument
log ("Reading: " ++ inputFile)
json <- readFile inputFile
case parseJson json of
Left err ->
throw err
Right data -> do
response <- httpPost (url data) (payload data)
log response.body
main = catchError myProgram (\err -> do
log "Oops! Something went wrong."
log "This is a bug. Please report it!"
log "Error details:"
log (inspect err))
(<|>) :: forall a. Aff _ a -> Aff _ a -> Aff _ a
httpGet "http://foo.com" <|> httpGet "http://bar.com"
attemptGet ["http://foo.com", "http://bar.com"]
where
attemptGet domains =
foldr (<|>) onAllFailed (map httpGet domains)
onAllFailed =
throwError (error "Could not GET from any domain")
newtype Par e a = Par (Aff e a)
Par (httpGet "http://foo.com") :: Par _ a
traverse :: forall a b.
(a -> Par _ b) -> Array a -> Par _ (Array b)
loadAll
[ "/images/player.png"
, "/images/wall.png"
, "/images/enemy.png"
]
where
loadAll urls =
runPar (traverse go urls)
go url =
Par (httpGet url)