Debian Codegraph @

examples/prism-purescript.html

raw symbols SCIP
1 <h2>Comments</h2>
2 <pre><code>-- Single line comment
3 {- Multi-line
4 comment -}</code></pre>
5
6 <h2>Strings and characters</h2>
7 <pre><code>'a'
8 '\n'
9 '\^A'
10 '\^]'
11 '\NUL'
12 '\23'
13 '\o75'
14 '\xFE'
15 "Here is a backslant \\ as well as \137, \
16 \a numeric escape character, and \^X, a control character."</code></pre>
17
18 <h2>Numbers</h2>
19 <pre><code>42
20 123.456
21 123.456e-789
22 1e+3
23 0o74
24 0XAF</code></pre>
25
26 <h2>Full example</h2>
27 <pre><code>module Codewars.Kata.SumFracts (sumFracts) where
28
29 import Prelude
30
31 import Data.Foldable (foldl)
32 import Data.BigInt (BigInt, fromInt, toString)
33 import Data.List (List, length)
34 import Data.Tuple (Tuple(..))
35 import Data.Maybe (Maybe(..))
36 import Data.Ord (abs, signum)
37
38 reduce :: Tuple BigInt BigInt -&gt; Tuple BigInt BigInt
39 reduce (Tuple num den) =
40 let gcd' = gcd num den
41 den' = den / gcd'
42 in Tuple (num / gcd' * (signum den')) (abs den')
43
44 sumFracts :: List (Tuple Int Int) -&gt; Maybe String
45 sumFracts fracts =
46 let fracts' = fracts &lt;#&gt; (\(Tuple n d) -&gt; Tuple (fromInt n) (fromInt d)) &gt;&gt;&gt; reduce
47
48 den = foldl (\acc (Tuple _ d) -&gt; lcm acc d) one fracts'
49 num = foldl (\acc (Tuple n d) -&gt; acc + n * (den / d)) zero fracts'
50
51 Tuple n d = reduce $ Tuple num den
52
53 in if length fracts == 0
54 then Nothing
55 else if d == one
56 then Just $ toString n
57 else Just $ (toString n) &gt;&lt; " " &gt;&lt; (toString d)</code></pre>