This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- stack --system-ghc runghc | |
{- | | |
Result of pair programming with [bumbleblym](https://github.com/bumbleblym) | |
He implemented most of the code below and suggested using parsers from base | |
rather than @getLine@ & @read@ to parse the input. | |
This increases code modularity and ease of refactoring. | |
Interesting parts: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
error[E0382]: use of moved value: `metal_shiny` | |
--> temp.rs:39:38 | |
| | |
37 | let metal_shiny = Metal::new(0.0); | |
| ----------- move occurs because `metal_shiny` has type `Metal`, which does not implement the `Copy` trait | |
38 | let sphere1 = Sphere::new(Box::new(metal_shiny)); | |
| ----------- value moved here | |
39 | let sphere2 = Sphere::new(Box::new(metal_shiny)); | |
| ^^^^^^^^^^^ value used here after move |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{- | | |
REFERENCES: | |
https://gist.github.com/lukechampine/a3956a840c603878fd9f | |
https://rosettacode.org/wiki/Y_combinator#Haskell | |
https://mvanier.livejournal.com/2897.html | |
GOAL: Implement recursion in languages which do not support **Explicit recursion** | |
Do so in an intuitive way | |
PREREQUISITES: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{- | | |
DESCRIPTION | |
This program parses valid NRICs from text. | |
NRICs are unique identification numbers given to Singaporeans and Permanent residents of Singapore. | |
SYSTEM | |
This runs on GHC 8.10.1 | |
These libraries should be included with your GHC distribution: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env stack | |
-- stack exec ghc --resolver lts-16.2 --package async --package criterion -- -threaded -O2 -rtsopts -with-rtsopts=-N | |
import Control.Concurrent.Async (async, mapConcurrently_) | |
import Control.Monad (replicateM_, void) | |
import Criterion.Main | |
main :: IO () | |
main = defaultMain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env stack | |
-- stack script --resolver lts-16.2 --package criterion --package relude --package text --package deepseq | |
{-# LANGUAGE DeriveGeneric #-} | |
{-# LANGUAGE NumericUnderscores #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
import Control.DeepSeq (NFData) | |
import Control.Monad (replicateM_, void) | |
import Criterion.Main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env stack | |
-- stack script --resolver lts-16.2 --package criterion | |
{-# LANGUAGE NumericUnderscores #-} | |
import Control.Monad (replicateM_, void) | |
import Criterion.Main | |
import Data.Foldable (foldl', foldr) | |
main :: IO () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env stack | |
-- stack exec ghc --resolver lts-16.2 --package time --package async --package text --package deepseq -- -prof -fprof-auto -threaded -O2 -rtsopts -with-rtsopts=-N -eventlog | |
{- | |
See if we can reproduce having to repeatedly generate environments | |
-} | |
{-# LANGUAGE BangPatterns #-} | |
{-# LANGUAGE NumericUnderscores #-} | |
{-# LANGUAGE RecordWildCards #-} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env stack | |
-- stack exec ghc --resolver lts-16.2 --package criterion -- -threaded -O2 -rtsopts -with-rtsopts=-N -eventlog | |
import Control.Monad (replicateM_, void) | |
import Criterion.Main | |
import Data.Foldable (foldl') | |
import Data.Tree | |
treeFoldStrict :: (b -> [a] -> b) -> b -> Tree a -> b | |
treeFoldStrict f init (Node val children) = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a | a | a | a | a | a |
---|
OlderNewer