-
-
Save ret/bb2feb29012c8a1ab85aa59c3de86e60 to your computer and use it in GitHub Desktop.
Single-file executable literate Haskell with Stack
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
#!/usr/bin/env stack | |
> -- stack --resolver lts-6 --install-ghc runghc --package classy-prelude --package lens --package wreq | |
Blah Blah words about this single file executable README goes here. | |
> {-# LANGUAGE DeriveAnyClass #-} | |
> {-# LANGUAGE DeriveGeneric #-} | |
> {-# LANGUAGE NoImplicitPrelude #-} | |
> {-# LANGUAGE OverloadedStrings #-} | |
explain explain | |
> import ClassyPrelude | |
> import Control.Lens | |
> import Network.Wreq | |
> import Data.Aeson | |
more explaining | |
> data IPInfo = IPInfo | |
> { ip :: Text | |
> , hostname :: Text | |
> , city :: Text | |
> , region :: Text | |
> , country :: Text | |
> , loc :: Text | |
> , org :: Text | |
> , postal :: Text | |
> } deriving (Show,Generic,ToJSON,FromJSON) | |
you are probably confused right now. let me explain | |
> main = do | |
> let opts = defaults & header "User-Agent" .~ ["curl/7.47.0"] | |
> eInfo <- eitherDecode . view responseBody <$> getWith opts "http://ipinfo.io" | |
> either print (putStrLn . city) (eInfo :: Either String IPInfo) | |
when I run it like this: | |
user@computer:~/src% ./README.lhs | |
Portland | |
you can see that I'm in Portland |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment