title: How can I parse roman numerals in Haskell's Parsec?
body: <p>I'm a Haskell beginner, and I'm trying to learn about Parsec by writing a parser that can consume either an arabic numeral, like "234," or a roman one, like "MCMLXIX." I found <a href="https://hackage.haskell.org/package/roman-numerals-0.5.1.5/docs/Text-Numeral-Roman.html" rel="nofollow noreferrer">the library roman-numerals</a>, and so I figured I'd try to use the <code>fromRoman</code> function somehow, in conjunction with Parsec, since I'll eventually need to get the arabic equivalent of the roman numeral. But I just don't quite yet know how to coerce the <code>Maybe</code> output of <code>fromRoman</code> into a <code>Parser</code>. This is what I have so far: </p>
  
  <pre><code>import Text.Parsec
  import Text.Parsec.Text (Parser)
  import Text.Numeral.Roman
  
  arabicNum :: Parser Int
  arabicNum = do
    n &lt;- many1 digit
    return (read n)
  
  isChapter :: Inline -&gt; Bool
  isChapter str = str == Str "CHAPTER"
  
  number :: Parser Int
  number = arabicNum &lt;|&gt; romanNum
  
  romanNum :: Parser Int
  romanNum = do
    str &lt;- many1 char
    return case (fromRoman str) of
      Just n -&gt; n
      Nothing -&gt; Nothing
  </code></pre>
  
  <p>But, no dice, since I don't quite yet know what I'm doing. </p>