Skip to content

Instantly share code, notes, and snippets.

@ret
Forked from dysinger/README.lhs
Created May 23, 2017 01:29
Show Gist options
  • Save ret/bb2feb29012c8a1ab85aa59c3de86e60 to your computer and use it in GitHub Desktop.
Save ret/bb2feb29012c8a1ab85aa59c3de86e60 to your computer and use it in GitHub Desktop.
Single-file executable literate Haskell with Stack
#!/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