Skip to content

Instantly share code, notes, and snippets.

View prednaz's full-sized avatar

Philipp prednaz

View GitHub Profile
{-# language MultiWayIf #-}
module MultiWayIfExample where
withoutExtension n =
if n < 10
then 'a'
else
if n < 100
then 'b'
{-# language LinearTypes #-}
module LinearExample where
id :: a ⊸ a
id a = a
{-# language
GADTSyntax,
FlexibleInstances
#-}
import Prelude hiding (String)
import qualified Prelude
main :: IO ()
main = print sample
import System.CPUTime (getCPUTime)
main :: IO ()
main =
do
timeStart <- getCPUTime
print expensiveComputation
timeEnd <- getCPUTime
print $ (fromInteger $ timeEnd - timeStart) / (fromInteger $ 10 ^ 12)
fn cartesian_product(scale: &mut (u32, u32)) -> Vec<(u32, u32)> {
(0..5)
.flat_map(|a| (0..5).map(|b| (a * scale.0, b * scale.1)))
.collect()
}
// error[E0373]: closure may outlive the current function, but it borrows `a`, which is owned by the current function
// --> src/main.rs:7:34
// |
// 7 | .flat_map(|a| (0..5).map(|b| (a * scale.0, b * scale.1)))
fn cartesian_product(scale: &mut (u32, u32)) -> Vec<(u32, u32)> {
(0..5)
.flat_map(|a| (0..5).map(|b| (a * scale.0, b * scale.1)))
.collect()
}
// error[E0373]: closure may outlive the current function, but it borrows `a`, which is owned by the current function
// --> src/main.rs:7:34
// |
// 7 | .flat_map(|a| (0..5).map(|b| (a * scale.0, b * scale.1)))
I: Reset h0: DEF "<" 2 122
P: 1 h1: DEF "|" 2 52
h2: DEF "if" 3 132
h3: DEF "*" 2 92
h4: DEF "not" 1 38
h5: DEF "false" 0 26
h6: DEF "-" 2 82
h7: DEF "+" 2 72
h8: DEF "main" 0 4
h9: DEF "true" 0 32
fromList
[
("main",(0,4)),
("a",(0,14)),
("b",(0,20)),
("false",(0,26)),
("true",(0,32)),
("not",(1,38)),
("negate",(1,45)),
("|",(2,52)),
main = a + b; a = 0; b = a;
I: Reset h0: DEF "<" 2 120
P: 1 h1: DEF "|" 2 50
h2: DEF "if" 3 130
h3: DEF "*" 2 90
h4: DEF "not" 1 36
h5: DEF "false" 0 24
h6: DEF "-" 2 80
h7: DEF "+" 2 70
h8: DEF "main" 0 4
h9: DEF "true" 0 30