Skip to content

Instantly share code, notes, and snippets.

@danclien
Created June 10, 2015 03:02
Show Gist options
  • Save danclien/33294c3a8781df5beff8 to your computer and use it in GitHub Desktop.
Save danclien/33294c3a8781df5beff8 to your computer and use it in GitHub Desktop.

Run from ghci. Must have attoparsec available via cabal repl.

:set -XOverloadedStrings

import Prelude
import Control.Applicative
import Data.Attoparsec.Text

data IPAddress = IPAddress Int Int Int Int deriving (Eq, Show)

let ipParser = IPAddress <$> decimal <* char '.' <*> decimal <* char '.' <*> decimal <* char '.' <*> decimal

-- Should return `Right (IPAddress 1 2 3 4)`
parseOnly ipParser "1.2.3.4"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment