Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

hashtags in Haskell

View Hashtags.hs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
import Data.Char (isAlpha)
import Text.Parsec
 
-- | Parses exactly one hashtag (and nothing else).
hashtag = do
char '#'
many letter
 
-- | Parse hashtags from a string (see the previous version for
-- a list-based version).
hashtags :: String -> [String]
hashtags s = always [] parsed
where parsed = parse (sepBy hashtag noTag) "hashtags" s
 
-- | Parse many things that aren't '#'.
noTag = many $ noneOf "#"
 
-- | When the Either is a Left, always return x. Otherwise, simply
-- unwrap the Right value.
always :: c -> Either a c -> c
always x = either (const x) id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.