Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/api/index.html

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions docs/examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -799,4 +799,41 @@ <h2>44-char.hell</h2><div class="sourceCode" id="cb1"><pre
class="sourceCode haskell"><code class="sourceCode haskell"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a>main <span class="ot">=</span> <span class="kw">do</span></span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a> line <span class="ot">&lt;-</span> Text.getLine</span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a> <span class="dt">IO</span><span class="op">.</span><span class="fu">print</span> <span class="op">$</span> Text.all (<span class="dt">Eq</span><span class="op">.</span>eq <span class="ch">&#39;x&#39;</span>) line</span></code></pre></div>
<h2>45-enum.hell</h2><div class="sourceCode" id="cb1"><pre
class="sourceCode haskell"><code class="sourceCode haskell"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a>main <span class="ot">=</span> <span class="kw">do</span></span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a> <span class="dt">IO</span><span class="op">.</span><span class="fu">print</span> <span class="op">$</span> List.take <span class="dv">5</span> <span class="op">$</span> <span class="dt">Enum</span><span class="op">.</span><span class="fu">enumFrom</span> <span class="dv">1</span></span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a> <span class="dt">IO</span><span class="op">.</span><span class="fu">print</span> <span class="op">$</span> <span class="dt">Enum</span><span class="op">.</span><span class="fu">enumFromTo</span> <span class="dv">1</span> <span class="dv">10</span></span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a> <span class="dt">IO</span><span class="op">.</span><span class="fu">print</span> <span class="op">$</span> List.take <span class="dv">5</span> <span class="op">$</span> <span class="dt">Enum</span><span class="op">.</span><span class="fu">enumFrom</span> <span class="ch">&#39;a&#39;</span></span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a> <span class="dt">IO</span><span class="op">.</span><span class="fu">print</span> <span class="op">$</span> List.take <span class="dv">5</span> <span class="op">$</span> <span class="dt">Enum</span><span class="op">.</span><span class="fu">enumFrom</span> <span class="dt">Bool</span><span class="op">.</span><span class="dt">False</span></span>
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a> <span class="dt">IO</span><span class="op">.</span><span class="fu">print</span> <span class="op">$</span> List.take <span class="dv">5</span> <span class="op">$</span> <span class="dt">Enum</span><span class="op">.</span><span class="fu">enumFrom</span> (<span class="dt">Int</span><span class="op">.</span><span class="fu">toInteger</span> <span class="dv">1</span>)</span>
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a> <span class="dt">IO</span><span class="op">.</span><span class="fu">print</span> <span class="op">$</span> List.take <span class="dv">5</span> <span class="op">$</span> <span class="dt">Enum</span><span class="op">.</span><span class="fu">enumFrom</span> <span class="op">$</span></span>
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true" tabindex="-1"></a> <span class="dt">Maybe</span><span class="op">.</span><span class="fu">maybe</span> (Error.error <span class="st">&quot;Bad day.&quot;</span>) Function.id <span class="op">$</span> Day.fromGregorianValid (<span class="dt">Int</span><span class="op">.</span><span class="fu">toInteger</span> <span class="dv">2020</span>) <span class="dv">01</span> <span class="dv">01</span></span>
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-10"><a href="#cb1-10" aria-hidden="true" tabindex="-1"></a> <span class="co">-- simple list generators</span></span>
<span id="cb1-11"><a href="#cb1-11" aria-hidden="true" tabindex="-1"></a> <span class="dt">IO</span><span class="op">.</span><span class="fu">print</span> [<span class="dv">1</span> <span class="op">..</span> <span class="dv">3</span>]</span>
<span id="cb1-12"><a href="#cb1-12" aria-hidden="true" tabindex="-1"></a> <span class="dt">IO</span><span class="op">.</span><span class="fu">print</span> <span class="op">$</span> List.take <span class="dv">5</span> [<span class="ch">&#39;a&#39;</span> <span class="op">..</span>]</span></code></pre></div>
<h2>46-exceptions.hell</h2><div class="sourceCode" id="cb1"><pre
class="sourceCode haskell"><code class="sourceCode haskell"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a>main <span class="ot">=</span> <span class="kw">do</span></span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a> <span class="kw">let</span><span class="ot"> noSuchFile ::</span> <span class="dt">Text</span> <span class="ot">=</span> <span class="st">&quot;no/such/file.txt&quot;</span></span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a> <span class="kw">let</span> printException <span class="ot">=</span> \e <span class="ot">-&gt;</span> <span class="kw">do</span> Text.hPutStr <span class="dt">IO</span><span class="op">.</span>stderr (<span class="dt">Show</span><span class="op">.</span><span class="fu">show</span> e <span class="op">&lt;&gt;</span> <span class="st">&quot;\n&quot;</span>)</span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a> <span class="dt">IO</span><span class="op">.</span><span class="fu">pure</span> <span class="st">&quot;&quot;</span></span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a> <span class="kw">let</span> catchAndPrintException <span class="ot">=</span> \action <span class="ot">-&gt;</span> SomeException.catch action printException</span>
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a> catchAndPrintException (Text.readFile noSuchFile)</span>
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true" tabindex="-1"></a> <span class="kw">let</span> file <span class="ot">=</span> <span class="st">&quot;file.txt&quot;</span></span>
<span id="cb1-10"><a href="#cb1-10" aria-hidden="true" tabindex="-1"></a> catchAndPrintException <span class="op">$</span></span>
<span id="cb1-11"><a href="#cb1-11" aria-hidden="true" tabindex="-1"></a> Exception.bracket</span>
<span id="cb1-12"><a href="#cb1-12" aria-hidden="true" tabindex="-1"></a> (<span class="dt">IO</span><span class="op">.</span>openFile file <span class="dt">IO</span><span class="op">.</span><span class="dt">ReadWriteMode</span>)</span>
<span id="cb1-13"><a href="#cb1-13" aria-hidden="true" tabindex="-1"></a> (\fileHandle <span class="ot">-&gt;</span> <span class="kw">do</span></span>
<span id="cb1-14"><a href="#cb1-14" aria-hidden="true" tabindex="-1"></a> <span class="dt">IO</span><span class="op">.</span>hClose fileHandle</span>
<span id="cb1-15"><a href="#cb1-15" aria-hidden="true" tabindex="-1"></a> Directory.removeFile file</span>
<span id="cb1-16"><a href="#cb1-16" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb1-17"><a href="#cb1-17" aria-hidden="true" tabindex="-1"></a> (\fileHandle <span class="ot">-&gt;</span> <span class="kw">do</span></span>
<span id="cb1-18"><a href="#cb1-18" aria-hidden="true" tabindex="-1"></a> <span class="dt">IO</span><span class="op">.</span>hSetBuffering fileHandle <span class="dt">IO</span><span class="op">.</span><span class="dt">NoBuffering</span></span>
<span id="cb1-19"><a href="#cb1-19" aria-hidden="true" tabindex="-1"></a> Text.hPutStr fileHandle <span class="st">&quot;don&#39;t buffer me&quot;</span></span>
<span id="cb1-20"><a href="#cb1-20" aria-hidden="true" tabindex="-1"></a> Text.decodeUtf8 <span class="op">&lt;$&gt;</span> <span class="dt">ByteString</span><span class="op">.</span>hGet fileHandle <span class="dv">10</span></span>
<span id="cb1-21"><a href="#cb1-21" aria-hidden="true" tabindex="-1"></a> )</span>
<span id="cb1-22"><a href="#cb1-22" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-23"><a href="#cb1-23" aria-hidden="true" tabindex="-1"></a> <span class="dt">IO</span><span class="op">.</span><span class="fu">pure</span> ()</span></code></pre></div>
</html>
23 changes: 23 additions & 0 deletions examples/46-exceptions.hell
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
main = do
let noSuchFile :: Text = "no/such/file.txt"
let printException = \e -> do Text.hPutStr IO.stderr (Show.show e <> "\n")
IO.pure ""
let catchAndPrintException = \action -> SomeException.catch action printException

catchAndPrintException (Text.readFile noSuchFile)

let file = "file.txt"
catchAndPrintException $
Exception.bracket
(IO.openFile file IO.ReadWriteMode)
(\fileHandle -> do
IO.hClose fileHandle
Directory.removeFile file
)
(\fileHandle -> do
IO.hSetBuffering fileHandle IO.NoBuffering
Text.hPutStr fileHandle "don't buffer me"
Text.decodeUtf8 <$> ByteString.hGet fileHandle 10
)

IO.pure ()
11 changes: 10 additions & 1 deletion src/Hell.hs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ import Data.ByteString.Builder (Builder)
import qualified Data.ByteString.Builder as Builder
import Control.Applicative (Alternative (..), optional)
import qualified Control.Concurrent as Concurrent
import Control.Exception (evaluate)
import Control.Exception (evaluate, SomeException)
import qualified Control.Exception as Exception
import Control.Monad.Reader
import Control.Monad.State.Strict
import Criterion.Measurement
Expand Down Expand Up @@ -864,6 +865,7 @@ instances =
instance0 @Show @Builder,
instance0 @Show @ExitCode,
instance0 @Show @Value,
instance0 @Show @SomeException,
entail1 @Eq @CI,
entail1 @Eq @[],
entail1 @Eq @Set,
Expand Down Expand Up @@ -1730,6 +1732,7 @@ supportedTypeConstructors =
("TimeOfDay", SomeTypeRep $ typeRep @TimeOfDay),
("Builder", SomeTypeRep $ typeRep @Builder),
("CI", SomeTypeRep $ typeRep @CI),
("SomeException", SomeTypeRep $ typeRep @SomeException),
-- Internal, hidden types
("hell:Hell.NilL", SomeTypeRep $ typeRep @('NilL)),
("hell:Hell.ConsL", SomeTypeRep $ typeRep @('ConsL)),
Expand Down Expand Up @@ -2394,6 +2397,12 @@ polyLits =
"Argument.help" options_help :: forall a. Text -> Options.Mod Options.ArgumentFields a
"Options.progDesc" options_progDesc :: forall a. Text -> Options.InfoMod a
"Options.header" options_header :: forall a. Text -> Options.InfoMod a

-- Exceptions
"Exception.finally" Exception.finally :: forall a b. IO a -> IO b -> IO a
"Exception.onException" Exception.onException :: forall a b. IO a -> IO b -> IO a
"Exception.bracket" Exception.bracket :: forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
"SomeException.catch" Exception.catch :: forall a. IO a -> (SomeException -> IO a) -> IO a
|]
in toplevel
)
Expand Down