Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# Last checked
# $ date
# Mon Feb 27 23:59:15 EEST 2017
2017-02-17 https://fsharpforfunandprofit.com/cap/
2017-02-17 https://fsharpforfunandprofit.com/turtle/
2017-02-17 https://fsharpforfunandprofit.com/video/
2016-12-05 https://fsharpforfunandprofit.com/posts/dependency-injection-1
2016-08-01 https://fsharpforfunandprofit.com/installing-and-using/
2016-06-23 https://fsharpforfunandprofit.com/parser/
2016-04-12 https://fsharpforfunandprofit.com/posts/happy-fsharp-day-2
2016-04-10 https://fsharpforfunandprofit.com/monadster/
2016-03-07 https://fsharpforfunandprofit.com/ddd/
2016-03-07 https://fsharpforfunandprofit.com/ettt/
2016-03-07 https://fsharpforfunandprofit.com/fppatterns/
2016-03-07 https://fsharpforfunandprofit.com/pbt/
2016-03-07 https://fsharpforfunandprofit.com/rop/
2015-12-07 https://fsharpforfunandprofit.com/site-contents/
2015-12-06 https://fsharpforfunandprofit.com/posts/13-ways-of-looking-at-a-turtle-3
2015-12-05 https://fsharpforfunandprofit.com/posts/13-ways-of-looking-at-a-turtle-2
2015-12-05 https://fsharpforfunandprofit.com/posts/13-ways-of-looking-at-a-turtle
2015-11-15 https://fsharpforfunandprofit.com/series/understanding-parser-combinators.html
2015-11-13 https://fsharpforfunandprofit.com/posts/understanding-parser-combinators-4
2015-11-12 https://fsharpforfunandprofit.com/posts/understanding-parser-combinators-3
2015-11-11 https://fsharpforfunandprofit.com/posts/understanding-parser-combinators-2
2015-11-10 https://fsharpforfunandprofit.com/posts/understanding-parser-combinators
2015-11-09 https://fsharpforfunandprofit.com/why-use-fsharp/
2015-10-16 https://fsharpforfunandprofit.com/
2015-09-01 https://fsharpforfunandprofit.com/rss.xml
2015-08-30 https://fsharpforfunandprofit.com/series/recursive-types-and-folds.html
2015-08-25 https://fsharpforfunandprofit.com/posts/recursive-types-and-folds-3b
2015-08-24 https://fsharpforfunandprofit.com/posts/recursive-types-and-folds-3
2015-08-23 https://fsharpforfunandprofit.com/posts/recursive-types-and-folds-2b
2015-08-22 https://fsharpforfunandprofit.com/posts/recursive-types-and-folds-2
2015-08-21 https://fsharpforfunandprofit.com/posts/recursive-types-and-folds-1b
2015-08-20 https://fsharpforfunandprofit.com/posts/recursive-types-and-folds
2015-08-14 https://fsharpforfunandprofit.com/posts/list-module-functions
2015-08-13 https://fsharpforfunandprofit.com/posts/type-size-and-design
2015-08-08 https://fsharpforfunandprofit.com/posts/elevated-world-7
2015-08-07 https://fsharpforfunandprofit.com/posts/elevated-world-6
2015-08-06 https://fsharpforfunandprofit.com/posts/elevated-world-5
2015-08-05 https://fsharpforfunandprofit.com/series/map-and-bind-and-apply-oh-my.html
2015-08-05 https://fsharpforfunandprofit.com/posts/elevated-world-4
2015-08-04 https://fsharpforfunandprofit.com/posts/elevated-world-3
2015-08-03 https://fsharpforfunandprofit.com/posts/elevated-world-2
2015-08-02 https://fsharpforfunandprofit.com/posts/elevated-world
2015-07-21 https://fsharpforfunandprofit.com/posts/typesafe-performance-with-compiler-directives
2015-07-18 https://fsharpforfunandprofit.com/posts/introvert-vs-extrovert
2015-07-16 https://fsharpforfunandprofit.com/series/handling-state.html
2015-07-15 https://fsharpforfunandprofit.com/posts/fsharp-decompiled
2015-07-09 https://fsharpforfunandprofit.com/posts/monadster-3
2015-07-08 https://fsharpforfunandprofit.com/posts/monadster-2
2015-07-07 https://fsharpforfunandprofit.com/posts/monadster
2015-06-30 https://fsharpforfunandprofit.com/posts/no-uml-diagrams
2015-04-12 https://fsharpforfunandprofit.com/posts/happy-fsharp-day
2015-02-17 https://fsharpforfunandprofit.com/csharp-light/
2015-02-17 https://fsharpforfunandprofit.com/series/a-functional-approach-to-authorization.html
2015-02-17 https://fsharpforfunandprofit.com/series/annotated-walkthroughs.html
2015-02-17 https://fsharpforfunandprofit.com/series/low-risk-ways-to-use-fsharp-at-work.html
2015-02-16 https://fsharpforfunandprofit.com/posts/enterprise-tic-tac-toe-2
2015-02-12 https://fsharpforfunandprofit.com/posts/enterprise-tic-tac-toe
2015-01-26 https://fsharpforfunandprofit.com/posts/is-your-language-unreasonable
2015-01-20 https://fsharpforfunandprofit.com/posts/capability-based-security-3
2015-01-19 https://fsharpforfunandprofit.com/posts/capability-based-security-2
2015-01-18 https://fsharpforfunandprofit.com/posts/capability-based-security
2014-12-12 https://fsharpforfunandprofit.com/posts/property-based-testing-2
2014-12-01 https://fsharpforfunandprofit.com/posts/property-based-testing
2014-10-16 https://fsharpforfunandprofit.com/posts/calculator-complete-v2
2014-10-15 https://fsharpforfunandprofit.com/posts/calculator-complete-v1
2014-10-14 https://fsharpforfunandprofit.com/posts/calculator-implementation
2014-10-13 https://fsharpforfunandprofit.com/posts/calculator-design
2014-04-24 https://fsharpforfunandprofit.com/posts/low-risk-ways-to-use-fsharp-at-work-5
2014-04-23 https://fsharpforfunandprofit.com/posts/low-risk-ways-to-use-fsharp-at-work-4
2014-04-22 https://fsharpforfunandprofit.com/posts/low-risk-ways-to-use-fsharp-at-work-3
2014-04-21 https://fsharpforfunandprofit.com/posts/low-risk-ways-to-use-fsharp-at-work-2
2014-04-20 https://fsharpforfunandprofit.com/posts/low-risk-ways-to-use-fsharp-at-work
2014-04-12 https://fsharpforfunandprofit.com/posts/roslyn-vs-fsharp-compiler
2014-01-12 https://fsharpforfunandprofit.com/posts/roman-numeral-kata
2013-11-02 https://fsharpforfunandprofit.com/series/domain-driven-design-in-fsharp.html
2013-10-25 https://fsharpforfunandprofit.com/posts/monoids-part3
2013-10-24 https://fsharpforfunandprofit.com/posts/monoids-part2
2013-10-23 https://fsharpforfunandprofit.com/posts/monoids-without-tears
2013-10-23 https://fsharpforfunandprofit.com/posts/book-announcement
2013-10-21 https://fsharpforfunandprofit.com/series/understanding-monoids.html
2013-10-20 https://fsharpforfunandprofit.com/about/
2013-10-20 https://fsharpforfunandprofit.com/subscribe.html
2013-07-02 https://fsharpforfunandprofit.com/csharp/union-types-in-csharp.html
2013-06-22 https://fsharpforfunandprofit.com/posts/railway-oriented-programming-carbonated
2013-06-12 https://fsharpforfunandprofit.com/series/dependency-cycles.html
2013-05-28 https://fsharpforfunandprofit.com/posts/cycles-and-modularity-in-the-wild
2013-05-27 https://fsharpforfunandprofit.com/posts/removing-cyclic-dependencies
2013-05-27 https://fsharpforfunandprofit.com/posts/cyclic-dependencies
2013-05-26 https://fsharpforfunandprofit.com/posts/recipe-part3
2013-05-22 https://fsharpforfunandprofit.com/series/a-recipe-for-a-functional-app.html
2013-05-14 https://fsharpforfunandprofit.com/posts/why-i-wont-be-writing-a-monad-tutorial
2013-05-11 https://fsharpforfunandprofit.com/posts/recipe-part2
2013-05-10 https://fsharpforfunandprofit.com/posts/recipe-part1
2013-04-12 https://fsharpforfunandprofit.com/posts/ten-reasons-not-to-use-a-functional-programming-language
2013-02-16 https://fsharpforfunandprofit.com/series/computation-expressions.html
2013-01-30 https://fsharpforfunandprofit.com/posts/computation-expressions-builder-part6
2013-01-29 https://fsharpforfunandprofit.com/posts/computation-expressions-builder-part5
2013-01-28 https://fsharpforfunandprofit.com/posts/computation-expressions-builder-part4
2013-01-27 https://fsharpforfunandprofit.com/posts/computation-expressions-builder-part3
2013-01-26 https://fsharpforfunandprofit.com/posts/computation-expressions-builder-part2
2013-01-25 https://fsharpforfunandprofit.com/posts/computation-expressions-builder-part1
2013-01-24 https://fsharpforfunandprofit.com/posts/computation-expressions-wrapper-types-part2
2013-01-23 https://fsharpforfunandprofit.com/posts/computation-expressions-wrapper-types
2013-01-22 https://fsharpforfunandprofit.com/posts/computation-expressions-bind
2013-01-21 https://fsharpforfunandprofit.com/posts/computation-expressions-continuations
2013-01-20 https://fsharpforfunandprofit.com/posts/computation-expressions-intro
2013-01-19 https://fsharpforfunandprofit.com/series/designing-with-types.html
2013-01-19 https://fsharpforfunandprofit.com/posts/designing-with-types-conclusion
2013-01-18 https://fsharpforfunandprofit.com/posts/designing-with-types-non-strings
2013-01-17 https://fsharpforfunandprofit.com/posts/designing-with-types-more-semantic-types
2013-01-16 https://fsharpforfunandprofit.com/posts/designing-with-types-representing-states
2013-01-15 https://fsharpforfunandprofit.com/posts/designing-with-types-discovering-the-domain
2013-01-14 https://fsharpforfunandprofit.com/posts/designing-with-types-making-illegal-states-unrepresentable
2013-01-13 https://fsharpforfunandprofit.com/posts/designing-with-types-single-case-dus
2013-01-12 https://fsharpforfunandprofit.com/posts/designing-with-types-intro
2012-09-25 https://fsharpforfunandprofit.com/learning-fsharp/
2012-09-25 https://fsharpforfunandprofit.com/search.html
2012-09-06 https://fsharpforfunandprofit.com/series/object-oriented-programming-in-fsharp.html
2012-09-02 https://fsharpforfunandprofit.com/troubleshooting-fsharp/
2012-08-27 https://fsharpforfunandprofit.com/series/lists-and-sequences.html
2012-08-27 https://fsharpforfunandprofit.com/series/porting-from-csharp.html
2012-08-02 https://fsharpforfunandprofit.com/posts/porting-to-csharp-getting-started
2012-08-01 https://fsharpforfunandprofit.com/posts/porting-to-csharp-intro
2012-07-17 https://fsharpforfunandprofit.com/posts/object-expressions
2012-07-16 https://fsharpforfunandprofit.com/posts/interfaces
2012-07-15 https://fsharpforfunandprofit.com/posts/inheritance
2012-07-14 https://fsharpforfunandprofit.com/posts/classes
2012-07-13 https://fsharpforfunandprofit.com/posts/object-oriented-intro
2012-07-12 https://fsharpforfunandprofit.com/posts/printf
2012-07-10 https://fsharpforfunandprofit.com/posts/units-of-measure
2012-07-10 https://fsharpforfunandprofit.com/posts/cli-types
2012-07-09 https://fsharpforfunandprofit.com/posts/type-inference
2012-07-09 https://fsharpforfunandprofit.com/posts/enum-types
2012-07-07 https://fsharpforfunandprofit.com/posts/stack-based-calculator
2012-06-30 https://fsharpforfunandprofit.com/posts/roman-numerals
2012-06-29 https://fsharpforfunandprofit.com/posts/pattern-matching-command-line
2012-06-28 https://fsharpforfunandprofit.com/posts/match-expression
2012-06-27 https://fsharpforfunandprofit.com/AnalyticsExclude.html
2012-06-24 https://fsharpforfunandprofit.com/series/recursion.html
2012-06-23 https://fsharpforfunandprofit.com/series/understanding-fsharp-types.html
2012-06-22 https://fsharpforfunandprofit.com/series/expressions-and-syntax.html
2012-06-12 https://fsharpforfunandprofit.com/series/optimization.html
2012-06-09 https://fsharpforfunandprofit.com/series/thinking-functionally.html
2012-06-08 https://fsharpforfunandprofit.com/series/why-use-fsharp.html
2012-06-07 https://fsharpforfunandprofit.com/posts/the-option-type
2012-06-06 https://fsharpforfunandprofit.com/posts/discriminated-unions
2012-06-05 https://fsharpforfunandprofit.com/posts/records
2012-06-04 https://fsharpforfunandprofit.com/posts/tuples
2012-06-03 https://fsharpforfunandprofit.com/posts/type-abbreviations
2012-06-02 https://fsharpforfunandprofit.com/posts/overview-of-types-in-fsharp
2012-06-01 https://fsharpforfunandprofit.com/posts/types-intro
2012-05-21 https://fsharpforfunandprofit.com/posts/exceptions
2012-05-20 https://fsharpforfunandprofit.com/posts/control-flow-expressions
2012-05-19 https://fsharpforfunandprofit.com/about/licence.html
2012-05-19 https://fsharpforfunandprofit.com/posts/naming-conventions
2012-05-18 https://fsharpforfunandprofit.com/posts/fsharp-syntax
2012-05-17 https://fsharpforfunandprofit.com/posts/understanding-fsharp-expressions
2012-05-17 https://fsharpforfunandprofit.com/posts/let-use-do
2012-05-16 https://fsharpforfunandprofit.com/posts/expressions-vs-statements
2012-05-15 https://fsharpforfunandprofit.com/posts/expressions-intro
2012-05-11 https://fsharpforfunandprofit.com/archives/
2012-05-11 https://fsharpforfunandprofit.com/posts/type-extensions
2012-05-10 https://fsharpforfunandprofit.com/posts/organizing-functions
2012-05-09 https://fsharpforfunandprofit.com/posts/function-signatures
2012-05-08 https://fsharpforfunandprofit.com/posts/defining-functions
2012-05-07 https://fsharpforfunandprofit.com/posts/function-composition
2012-05-06 https://fsharpforfunandprofit.com/posts/partial-application
2012-05-05 https://fsharpforfunandprofit.com/posts/currying
2012-05-04 https://fsharpforfunandprofit.com/posts/how-types-work-with-functions
2012-05-03 https://fsharpforfunandprofit.com/posts/function-values-and-simple-values
2012-05-02 https://fsharpforfunandprofit.com/posts/mathematical-functions
2012-05-01 https://fsharpforfunandprofit.com/posts/thinking-functionally-intro
2012-04-30 https://fsharpforfunandprofit.com/posts/why-use-fsharp-conclusion
2012-04-29 https://fsharpforfunandprofit.com/posts/completeness-anything-csharp-can-do
2012-04-28 https://fsharpforfunandprofit.com/posts/completeness-seamless-dotnet-interop
2012-04-27 https://fsharpforfunandprofit.com/posts/completeness-intro
2012-04-26 https://fsharpforfunandprofit.com/posts/concurrency-reactive
2012-04-25 https://fsharpforfunandprofit.com/posts/concurrency-actor-model
2012-04-24 https://fsharpforfunandprofit.com/posts/concurrency-async-and-parallel
2012-04-23 https://fsharpforfunandprofit.com/posts/concurrency-intro
2012-04-22 https://fsharpforfunandprofit.com/posts/designing-for-correctness
2012-04-21 https://fsharpforfunandprofit.com/posts/correctness-type-checking
2012-04-20 https://fsharpforfunandprofit.com/posts/correctness-exhaustive-pattern-matching
2012-04-19 https://fsharpforfunandprofit.com/posts/correctness-immutability
2012-04-18 https://fsharpforfunandprofit.com/posts/correctness-intro
2012-04-17 https://fsharpforfunandprofit.com/posts/convenience-active-patterns
2012-04-16 https://fsharpforfunandprofit.com/posts/convenience-partial-application
2012-04-15 https://fsharpforfunandprofit.com/posts/convenience-functions-as-interfaces
2012-04-14 https://fsharpforfunandprofit.com/posts/convenience-types
2012-04-13 https://fsharpforfunandprofit.com/posts/convenience-intro
2012-04-12 https://fsharpforfunandprofit.com/posts/conciseness-pattern-matching
2012-04-11 https://fsharpforfunandprofit.com/posts/conciseness-functions-as-building-blocks
2012-04-10 https://fsharpforfunandprofit.com/posts/conciseness-extracting-boilerplate
2012-04-09 https://fsharpforfunandprofit.com/posts/conciseness-type-definitions
2012-04-08 https://fsharpforfunandprofit.com/posts/conciseness-type-inference
2012-04-07 https://fsharpforfunandprofit.com/posts/conciseness-intro
2012-04-06 https://fsharpforfunandprofit.com/posts/key-concepts
2012-04-05 https://fsharpforfunandprofit.com/posts/fvsc-download
2012-04-04 https://fsharpforfunandprofit.com/posts/fvsc-quicksort
2012-04-03 https://fsharpforfunandprofit.com/posts/fvsc-sum-of-squares
2012-04-02 https://fsharpforfunandprofit.com/posts/fsharp-in-60-seconds
2012-04-01 https://fsharpforfunandprofit.com/posts/why-use-fsharp-intro
name: SortW
version: 0.0.1
build-type: Simple
cabal-version: >=1.10
executable SortW
main-is: SortW.hs
build-depends: base, HTTP, parsec
ghc-options: -Wall -fno-warn-unused-do-bind
default-language: Haskell2010
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiParamTypeClasses #-}
module Main (main) where
import Data.Function (on)
import Data.Functor.Identity (Identity)
import Data.List (sortBy)
import Network.HTTP (getRequest, getResponseBody, simpleHTTP)
import Text.Parsec (ParsecT, Stream, char, digit, letter,
many, many1, noneOf, parse, spaces,
string, try, (<|>))
data Xml =
Elem String [Attribute] [Xml]
| Decl String
| Body String
newtype Attribute =
Attribute (String, String)
root :: ParsecT String u Identity Xml
root = Decl <$> (string "<?xml" *> many (noneOf "?>") <* string "?>")
document :: ParsecT String () Identity [Xml]
document = do
spaces
x <- try root <|> tag
spaces
y <- many tag
spaces
return (x : y)
tag :: ParsecT String u Identity Xml
tag = do
char '<'
spaces
name <- many (letter <|> digit)
spaces
attr <- many attribute
spaces
try (string "/>" <|> string ">")
body <- many (spaces *> try tag <|> text)
endTag name
spaces
return $ Elem name attr body
endTag :: Stream s m Char => String -> ParsecT s u m String
endTag str = string "</" *> string str <* char '>'
text :: ParsecT String u Identity Xml
text = Body <$> many1 (noneOf "><")
attribute :: ParsecT String u Identity Attribute
attribute = do
name <- many (noneOf "= />")
spaces
char '='
spaces
char '"'
value <- many (noneOf ['"'])
char '"'
spaces
return $ Attribute (name, value)
searchTag :: String -> [Xml] -> [Xml]
searchTag _ [] = []
searchTag name (Decl _:xs) = searchTag name xs
searchTag name (Body _:xs) = searchTag name xs
searchTag name (Elem s attr x:xs)
| s == name = Elem s attr x:searchTag name xs
| otherwise = searchTag name (x ++ xs)
extractBody :: Xml -> String
extractBody (Elem _ _ (Body bd:_)) = bd
extractBody _ = ""
xmlParse :: String -> [Xml]
xmlParse s =
case parse document "" s of
Right r -> r
Left _ -> []
getUrl :: String -> IO String
getUrl url = simpleHTTP (getRequest url) >>= getResponseBody
main :: IO ()
main = do
sitemapString <- getUrl "http://fsharpforfunandprofit.com/sitemap.xml"
let parsedXml = xmlParse sitemapString
find name = map extractBody $ searchTag name parsedXml
formatted = unlines $ map
(\x -> fst x ++ " " ++ snd x)
(sortBy (flip compare `on` fst) $ zip (find "lastmod") (find "loc"))
putStr formatted
resolver: lts-6.27
@moodmosaic

This comment has been minimized.

Copy link
Owner Author

commented Feb 27, 2017

stack build && stack exec -- SortW > output.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.