title: Haskell regex context ambiguous type despite explicit Bool type annotation, succeeds in ghci
body: <p>This works in an interpreter session</p>
  
  <pre><code>λ&gt; import Text.Regex.Base
  λ&gt; import Text.Regex.Posix
  λ&gt; import Data.List (sort)
  λ&gt; import System.Directory
  
  λ&gt; ls &lt;- getDirectoryContents "."
  λ&gt; let csvs = sort $ filter (\x -&gt; x =~ "csv$" :: Bool) ls
  λ&gt; recent = last csvs
  </code></pre>
  
  <p>This is great and gives me exactly what I need.</p>
  
  <p>However, the same code fails to compile in a script:</p>
  
  <pre><code>t10.hs:40:35-45: error: …
      • Ambiguous type variable ‘source0’ arising from a use of ‘=~’
        prevents the constraint ‘(RegexMaker
                                    Regex CompOption ExecOption source0)’ from being solved.
        Probable fix: use a type annotation to specify what ‘source0’ should be.
        These potential instances exist:
          instance RegexMaker Regex CompOption ExecOption C.ByteString
            -- Defined in ‘Text.Regex.Posix.ByteString’
          instance RegexMaker Regex CompOption ExecOption LB.ByteString
            -- Defined in ‘Text.Regex.Posix.ByteString.Lazy’
      • In the expression: x =~ "csv$" :: Bool
        In the first argument of ‘filter’, namely
          ‘(\ x -&gt; x =~ "csv$" :: Bool)’
        In the second argument of ‘($)’, namely
          ‘filter (\ x -&gt; x =~ "csv$" :: Bool) ls’
  t10.hs:40:40-45: error: …
      • Ambiguous type variable ‘source0’ arising from the literal ‘"csv$"’
        prevents the constraint ‘(Data.String.IsString
                                    source0)’ from being solved.
        Probable fix: use a type annotation to specify what ‘source0’ should be.
  </code></pre>
  
  <p>I have an explicit <code>:: Bool</code> context at the end to provide exactly this information.  Why would this be succeeding in ghci but failing to catch this same instruction when compiling, and how can I fix it?</p>