]> Git — Sourcephile - comptalang.git/blob - cli/Hcompta/Expr/If.hs
Remove old Yesod scaffolding.
[comptalang.git] / cli / Hcompta / Expr / If.hs
1 {-# LANGUAGE DefaultSignatures #-}
2 {-# LANGUAGE NoImplicitPrelude #-}
3 {-# OPTIONS_GHC -fno-warn-tabs #-}
4
5 module Hcompta.Expr.If where
6
7 import Control.Monad (Monad(..), when)
8 import Data.Bool
9
10 import Hcompta.Expr.Dup
11
12 -- * Class 'Expr_If'
13
14 class Expr_If repr where
15 default if_ :: Monad repr => repr Bool -> repr a -> repr a -> repr a
16 default when_ :: Monad repr => repr Bool -> repr () -> repr ()
17
18 if_ :: repr Bool -> repr a -> repr a -> repr a
19 if_ m ok ko = do
20 m' <- m
21 if m' then ok else ko
22
23 when_ :: repr Bool -> repr () -> repr ()
24 when_ m ok = do
25 m' <- m
26 when m' ok
27
28 instance -- Expr_If Dup
29 ( Expr_If r1
30 , Expr_If r2
31 ) => Expr_If (Dup r1 r2) where
32 if_ (c1 `Dup` c2) (ok1 `Dup` ok2) (ko1 `Dup` ko2) =
33 if_ c1 ok1 ko1 `Dup`
34 if_ c2 ok2 ko2
35 when_ (c1 `Dup` c2) (ok1 `Dup` ok2) =
36 when_ c1 ok1 `Dup`
37 when_ c2 ok2