Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Qinka committed Sep 18, 2017
2 parents f01aeea + 884f275 commit 31eeaa4
Show file tree
Hide file tree
Showing 25 changed files with 820 additions and 0 deletions.
1 change: 1 addition & 0 deletions .infos/bottleneck.1.post.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"summary":{"Left":"post/haskell/bottleneck.1.sum.md"},"path":"/b/haskell/bottleneck/1","whose":"QInkqa","create-time":"2017-02-28T14:54:13.728015Z","id":"bottleneck.1.post","html":"post/haskell/bottleneck.1.md","title":"Bottleneck 1","type":"post","tags":["blog","highlight","code","haskell"]}
1 change: 1 addition & 0 deletions .infos/crash.your.ghc.1.post.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"summary":{"Left":"post/haskell/crash.your.ghc.1.sum.md"},"path":"/b/haskell/crash-your-ghc/1","whose":"Qinka","create-time":"2017-03-01T01:00:23.178984Z","id":"crash.your.ghc.1.post","html":"post/haskell/crash.your.ghc.1.md","title":"Crash your GHC 1","type":"post","tags":["blog","code","highlight"]}
1 change: 1 addition & 0 deletions .infos/debug.in.ghci.1.post.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"summary":{"Left":"post/haskell/debug.in.ghci.1.sum.md"},"path":"/b/haskell/debug-with-ghci/1","whose":"Qinka","create-time":"2017-02-27T13:23:25.343155Z","id":"debug.in.ghci.1.post","html":"post/haskell/debug.in.ghci.1.md","title":"Debug with GHCi 1","type":"post","tags":["blog","highlight","code","haskell"]}
1 change: 1 addition & 0 deletions .infos/memoization-in-haskell.1.img.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"summary":{"Right":" "},"mime":"image/png","path":"/img/haskell/mem_right_one.png","whose":"Qinka","create-time":"2017-09-18T10:39:42.989391Z","binary":"img/haskell/mem_right_one.png","id":"memoization-in-haskell.1.img","title":"Memoization in Haskell figure 1","type":"binary","tags":["img"]}
1 change: 1 addition & 0 deletions .infos/memoization-in-haskell.2.img.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"summary":{"Right":" "},"mime":"image/png","path":"/img/haskell/mem_error_one.png","whose":"Qinka","create-time":"2017-09-18T10:40:00.702901Z","binary":"img/haskell/mem_error_one.png","id":"memoization-in-haskell.2.img","title":"Memoization in Haskell figure 1","type":"binary","tags":["img"]}
1 change: 1 addition & 0 deletions .infos/memoization-in-haskell.3.img.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"summary":{"Right":" "},"mime":"image/png","path":"/img/haskell/mem_error_two.png","whose":"Qinka","create-time":"2017-09-18T10:39:50.438584Z","binary":"img/haskell/mem_error_two.png","id":"memoization-in-haskell.3.img","title":"Memoization in Haskell figure 1","type":"binary","tags":["img"]}
1 change: 1 addition & 0 deletions .infos/memoization-in-haskell.post.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"summary":{"Left":"post/haskell/memoization_in_haskell.sum.md"},"path":"/b/haskell/memoization","whose":"Qinka","create-time":"2017-03-23T14:26:10.1791938Z","id":"memoization-in-haskell.post","html":"post/haskell/memoization_in_haskell.md","title":"Memoization in Haskell","type":"post","tags":["code","highlight","post","blog","haskell"]}
1 change: 1 addition & 0 deletions .infos/overloadedlabels.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"summary":{"Left":"post/haskell/overloadedlabels.sum.md"},"path":"/b/haskell/extension/overloadedlabels","whose":"Qinka","create-time":"2017-01-01T05:26:03.55291Z","id":"overloadedlabels","html":"post/haskell/overloadedlabels.md","title":"OverloadedLables","type":"post","tags":["highlight","blog","haskell","haskell language extensions"]}
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,4 @@ include deeplearning.mk
include post-docker.mk
include post-euterpea.mk
include post-fpga.mk
include post-haskell.mk
Binary file added img/haskell/mem_error_one.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/haskell/mem_error_two.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/haskell/mem_right_one.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
188 changes: 188 additions & 0 deletions post-haskell.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
bottleneck.1.post: post/haskell/bottleneck.1.md post/haskell/bottleneck.1.sum.md
@pandoc -o .ignore/bottleneck.1.html post/haskell/bottleneck.1.md
@pandoc -o .ignore/bottleneck.1.sum.html post/haskell/bottleneck.1.sum.md
@$(ECHO) $(CURL_PATH) $(CURL_DETAIL) -X PUT \
' -F "type=post" ' \
' -F "create-time=2017-02-28 14:54:13.728015 UTC" ' \
' -F "update-time=$(IH_NOW)" ' \
' -F "title=Bottleneck 1" ' \
' -F "[email protected]/bottleneck.1.html" ' \
' -F "sha-file-name=/`$(MD5) $(PRIVATE_KEY).pub`" ' \
' -F "[email protected]/bottleneck.1.sum.html" ' \
' -F "whose=QInkqa" ' \
' -F "tag=blog" ' \
' -F "tag=highlight" ' \
' -F "tag=code" ' \
' -F "tag=haskell" ' \
$(SITE_URL)/b/haskell/bottleneck/1 | $(IH_PATH) -m -f '$(IH_DELAY)' -p '$(PRIVATE_KEY)' -d '$(SITE_DELTA)' -v | $(SHELL)

bottleneck.1.post.del:
@$(ECHO) $(CURL_PATH) $(CURL_DETAIL) -X DELETE \
' -F "type=post" ' \
' -F "sha-file-name=/`$(MD5) $(PRIVATE_KEY).pub`" ' \
$(SITE_URL)/b/haskell/bottleneck/1 | $(IH_PATH) -m -f '$(IH_DELAY)' -p '$(PRIVATE_KEY)' -d '$(SITE_DELTA)' -v | $(SHELL)


crash.your.ghc.1.post: post/haskell/crash.your.ghc.1.md post/haskell/crash.your.ghc.1.sum.md
@pandoc -o .ignore/crash.your.ghc.1.html post/haskell/crash.your.ghc.1.md
@pandoc -o .ignore/crash.your.ghc.1.sum.html post/haskell/crash.your.ghc.1.sum.md
@$(ECHO) $(CURL_PATH) $(CURL_DETAIL) -X PUT \
' -F "type=post" ' \
' -F "create-time=2017-03-01 01:00:23.178984 UTC" ' \
' -F "update-time=$(IH_NOW)" ' \
' -F "title=Crash your GHC 1" ' \
' -F "[email protected]/crash.your.ghc.1.html" ' \
' -F "sha-file-name=/`$(MD5) $(PRIVATE_KEY).pub`" ' \
' -F "[email protected]/crash.your.ghc.1.sum.html" ' \
' -F "whose=Qinka" ' \
' -F "tag=blog" ' \
' -F "tag=code" ' \
' -F "tag=highlight" ' \
$(SITE_URL)/b/haskell/crash-your-ghc/1 | $(IH_PATH) -m -f '$(IH_DELAY)' -p '$(PRIVATE_KEY)' -d '$(SITE_DELTA)' -v | $(SHELL)

crash.your.ghc.1.post.del:
@$(ECHO) $(CURL_PATH) $(CURL_DETAIL) -X DELETE \
' -F "type=post" ' \
' -F "sha-file-name=/`$(MD5) $(PRIVATE_KEY).pub`" ' \
$(SITE_URL)/b/haskell/crash-your-ghc/1 | $(IH_PATH) -m -f '$(IH_DELAY)' -p '$(PRIVATE_KEY)' -d '$(SITE_DELTA)' -v | $(SHELL)


debug.in.ghci.1.post: post/haskell/debug.in.ghci.1.md post/haskell/debug.in.ghci.1.sum.md
@pandoc -o .ignore/debug.in.ghci.1.html post/haskell/debug.in.ghci.1.md
@pandoc -o .ignore/debug.in.ghci.1.sum.html post/haskell/debug.in.ghci.1.sum.md
@$(ECHO) $(CURL_PATH) $(CURL_DETAIL) -X PUT \
' -F "type=post" ' \
' -F "create-time=2017-02-27 13:23:25.343155 UTC" ' \
' -F "update-time=$(IH_NOW)" ' \
' -F "title=Debug with GHCi 1" ' \
' -F "[email protected]/debug.in.ghci.1.html" ' \
' -F "sha-file-name=/`$(MD5) $(PRIVATE_KEY).pub`" ' \
' -F "[email protected]/debug.in.ghci.1.sum.html" ' \
' -F "whose=Qinka" ' \
' -F "tag=blog" ' \
' -F "tag=highlight" ' \
' -F "tag=code" ' \
' -F "tag=haskell" ' \
$(SITE_URL)/b/haskell/debug-with-ghci/1 | $(IH_PATH) -m -f '$(IH_DELAY)' -p '$(PRIVATE_KEY)' -d '$(SITE_DELTA)' -v | $(SHELL)

debug.in.ghci.1.post.del:
@$(ECHO) $(CURL_PATH) $(CURL_DETAIL) -X DELETE \
' -F "type=post" ' \
' -F "sha-file-name=/`$(MD5) $(PRIVATE_KEY).pub`" ' \
$(SITE_URL)/b/haskell/debug-with-ghci/1 | $(IH_PATH) -m -f '$(IH_DELAY)' -p '$(PRIVATE_KEY)' -d '$(SITE_DELTA)' -v | $(SHELL)


memoization-in-haskell.1.img: img/haskell/mem_right_one.png
@$(ECHO) $(CURL_PATH) $(CURL_DETAIL) -X PUT \
' -F "type=binary" ' \
' -F "create-time=2017-09-18 10:39:42.989391 UTC" ' \
' -F "update-time=$(IH_NOW)" ' \
' -F "title=Memoization in Haskell figure 1" ' \
' -F "binary=@img/haskell/mem_right_one.png" ' \
' -F "sha-file-name=/`$(MD5) $(PRIVATE_KEY).pub`" ' \
' -F "summary= " ' \
' -F "mime=image/png" ' \
' -F "whose=Qinka" ' \
' -F "tag=img" ' \
$(SITE_URL)/img/haskell/mem_right_one.png | $(IH_PATH) -m -f '$(IH_DELAY)' -p '$(PRIVATE_KEY)' -d '$(SITE_DELTA)' -v | $(SHELL)

memoization-in-haskell.1.img.del:
@$(ECHO) $(CURL_PATH) $(CURL_DETAIL) -X DELETE \
' -F "type=binary" ' \
' -F "sha-file-name=/`$(MD5) $(PRIVATE_KEY).pub`" ' \
$(SITE_URL)/img/haskell/mem_right_one.png | $(IH_PATH) -m -f '$(IH_DELAY)' -p '$(PRIVATE_KEY)' -d '$(SITE_DELTA)' -v | $(SHELL)


memoization-in-haskell.2.img: img/haskell/mem_error_one.png
@$(ECHO) $(CURL_PATH) $(CURL_DETAIL) -X PUT \
' -F "type=binary" ' \
' -F "create-time=2017-09-18 10:40:00.702901 UTC" ' \
' -F "update-time=$(IH_NOW)" ' \
' -F "title=Memoization in Haskell figure 1" ' \
' -F "binary=@img/haskell/mem_error_one.png" ' \
' -F "sha-file-name=/`$(MD5) $(PRIVATE_KEY).pub`" ' \
' -F "summary= " ' \
' -F "mime=image/png" ' \
' -F "whose=Qinka" ' \
' -F "tag=img" ' \
$(SITE_URL)/img/haskell/mem_error_one.png | $(IH_PATH) -m -f '$(IH_DELAY)' -p '$(PRIVATE_KEY)' -d '$(SITE_DELTA)' -v | $(SHELL)

memoization-in-haskell.2.img.del:
@$(ECHO) $(CURL_PATH) $(CURL_DETAIL) -X DELETE \
' -F "type=binary" ' \
' -F "sha-file-name=/`$(MD5) $(PRIVATE_KEY).pub`" ' \
$(SITE_URL)/img/haskell/mem_error_one.png | $(IH_PATH) -m -f '$(IH_DELAY)' -p '$(PRIVATE_KEY)' -d '$(SITE_DELTA)' -v | $(SHELL)


memoization-in-haskell.3.img: img/haskell/mem_error_two.png
@$(ECHO) $(CURL_PATH) $(CURL_DETAIL) -X PUT \
' -F "type=binary" ' \
' -F "create-time=2017-09-18 10:39:50.438584 UTC" ' \
' -F "update-time=$(IH_NOW)" ' \
' -F "title=Memoization in Haskell figure 1" ' \
' -F "binary=@img/haskell/mem_error_two.png" ' \
' -F "sha-file-name=/`$(MD5) $(PRIVATE_KEY).pub`" ' \
' -F "summary= " ' \
' -F "mime=image/png" ' \
' -F "whose=Qinka" ' \
' -F "tag=img" ' \
$(SITE_URL)/img/haskell/mem_error_two.png | $(IH_PATH) -m -f '$(IH_DELAY)' -p '$(PRIVATE_KEY)' -d '$(SITE_DELTA)' -v | $(SHELL)

memoization-in-haskell.3.img.del:
@$(ECHO) $(CURL_PATH) $(CURL_DETAIL) -X DELETE \
' -F "type=binary" ' \
' -F "sha-file-name=/`$(MD5) $(PRIVATE_KEY).pub`" ' \
$(SITE_URL)/img/haskell/mem_error_two.png | $(IH_PATH) -m -f '$(IH_DELAY)' -p '$(PRIVATE_KEY)' -d '$(SITE_DELTA)' -v | $(SHELL)


memoization-in-haskell.post: post/haskell/memoization_in_haskell.md post/haskell/memoization_in_haskell.sum.md
@pandoc -o .ignore/memoization_in_haskell.html post/haskell/memoization_in_haskell.md
@pandoc -o .ignore/memoization_in_haskell.sum.html post/haskell/memoization_in_haskell.sum.md
@$(ECHO) $(CURL_PATH) $(CURL_DETAIL) -X PUT \
' -F "type=post" ' \
' -F "create-time=2017-03-23 14:26:10.1791938 UTC" ' \
' -F "update-time=$(IH_NOW)" ' \
' -F "title=Memoization in Haskell" ' \
' -F "[email protected]/memoization_in_haskell.html" ' \
' -F "sha-file-name=/`$(MD5) $(PRIVATE_KEY).pub`" ' \
' -F "[email protected]/memoization_in_haskell.sum.html" ' \
' -F "whose=Qinka" ' \
' -F "tag=code" ' \
' -F "tag=highlight" ' \
' -F "tag=post" ' \
' -F "tag=blog" ' \
' -F "tag=haskell" ' \
$(SITE_URL)/b/haskell/memoization | $(IH_PATH) -m -f '$(IH_DELAY)' -p '$(PRIVATE_KEY)' -d '$(SITE_DELTA)' -v | $(SHELL)

memoization-in-haskell.post.del:
@$(ECHO) $(CURL_PATH) $(CURL_DETAIL) -X DELETE \
' -F "type=post" ' \
' -F "sha-file-name=/`$(MD5) $(PRIVATE_KEY).pub`" ' \
$(SITE_URL)/b/haskell/memoization | $(IH_PATH) -m -f '$(IH_DELAY)' -p '$(PRIVATE_KEY)' -d '$(SITE_DELTA)' -v | $(SHELL)


overloadedlabels: post/haskell/overloadedlabels.md post/haskell/overloadedlabels.sum.md
@pandoc -o .ignore/overloadedlabels.html post/haskell/overloadedlabels.md
@pandoc -o .ignore/overloadedlabels.sum.html post/haskell/overloadedlabels.sum.md
@$(ECHO) $(CURL_PATH) $(CURL_DETAIL) -X PUT \
' -F "type=post" ' \
' -F "create-time=2017-01-01 05:26:03.55291 UTC" ' \
' -F "update-time=$(IH_NOW)" ' \
' -F "title=OverloadedLables" ' \
' -F "[email protected]/overloadedlabels.html" ' \
' -F "sha-file-name=/`$(MD5) $(PRIVATE_KEY).pub`" ' \
' -F "[email protected]/overloadedlabels.sum.html" ' \
' -F "whose=Qinka" ' \
' -F "tag=highlight" ' \
' -F "tag=blog" ' \
' -F "tag=haskell" ' \
' -F "tag=haskell language extensions" ' \
$(SITE_URL)/b/haskell/extension/overloadedlabels | $(IH_PATH) -m -f '$(IH_DELAY)' -p '$(PRIVATE_KEY)' -d '$(SITE_DELTA)' -v | $(SHELL)

overloadedlabels.del:
@$(ECHO) $(CURL_PATH) $(CURL_DETAIL) -X DELETE \
' -F "type=post" ' \
' -F "sha-file-name=/`$(MD5) $(PRIVATE_KEY).pub`" ' \
$(SITE_URL)/b/haskell/extension/overloadedlabels | $(IH_PATH) -m -f '$(IH_DELAY)' -p '$(PRIVATE_KEY)' -d '$(SITE_DELTA)' -v | $(SHELL)


15 changes: 15 additions & 0 deletions post/haskell/bottleneck.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@


# Six Items to Avoid Bad Performance

1. Understanding lazy evaluation schemas and their implications

2. Handing intended and unintended value memoization (CAFs)

3. Utilizing(guarded) recursion and the worker/wrapper parttern efficiently

4. Using accumulators correctlu to avoid space leaks

5. Analyzing strictness and space usage of Haskell programs

6. Important compiler code optimizations, inlining and fusion
3 changes: 3 additions & 0 deletions post/haskell/bottleneck.1.sum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Summary

This series of blog is about the notes for bottleneck, when I'm reading the *Haskell High Performance Programming*.
79 changes: 79 additions & 0 deletions post/haskell/crash.your.ghc.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@

# Conventions

This blog's examples is running on the macOS 10.12 with GHC-8.0.2.
In the different environments, the **CONDITIONs** of the crash might be different, except **BUGs**.

# 1. Heap Exhausted (1)

There is an example for crash your GHCi, via "Heap Exhausted".
We fire up the GHCi with command: `ghci +RTS -M40m`.
Then we calculate the sum of `[1..10^6]`, with the following codes:

```
> import Prelude as P
P > import Data.List as L
P L> :set +s
P L> L.foldl' (+) 0 [1..10^6]
500000500000
(0.10 secs, 88,080,384 bytes)
P L> let xs = [1..10^6] :: [Int]
(0.00 secs, 64,112 bytes)
P L> L.foldl' (+) 0 [1..10^6] :: Int
500000500000
(0.10 secs, 96,078,704 bytes)
P L> L.foldl' (+) 0( [1..10^6] :: [Int])
500000500000
(0.03 secs, 96,074,544 bytes)
P L> L.foldl' (+) 0 xs
<interactive>: Heap exhausted;
<interactive>: Current maximum heap size is 41943040 bytes (40 MB).
<interactive>: Use `+RTS -M<size>' to increase it.
```

Because of the binding `xs`, the `xs` will be a shared value, and GC will not recycle it. Then the space leak, and crash.

# 2. Impossible Happened (1) **[BUG]**

Fire up your GHCi, and do the following do.

```
Prelude> :set -fbreak-on-exception
Prelude> import Control.Exception
Prelude Control.Exception> :trace read "a" :: Int
Stopped in <exception thrown>, <unknown>
_exception :: e = _
[<unknown>] Prelude Control.Exception> _exception
<interactive>:4:1: error:
• No instance for (Show e) arising from a use of ‘print’
Cannot resolve unknown runtime type ‘e’
Use :print or :force to determine these types
Relevant bindings include it :: e (bound at <interactive>:4:1)
These potential instances exist:
instance Show Ordering -- Defined in ‘GHC.Show’
instance Show Integer -- Defined in ‘GHC.Show’
instance Show a => Show (Maybe a) -- Defined in ‘GHC.Show’
...plus 22 others
...plus 11 instances involving out-of-scope types
(use -fprint-potential-instances to see them all)
• In a stmt of an interactive GHCi command: print it
[<unknown>] Prelude Control.Exception> _exception :: SomeException
<interactive>:5:1: error:<interactive>: panic! (the 'impossible' happened)
(GHC version 8.0.2 for x86_64-apple-darwin):
No skolem info: e_ESget[rt]
Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
[<unknown>] Prelude Control.Exception>
```

When trying to evaluate `_exception`, the GHCi crash for an *"no skolem info"*. But you still can do the same things using `:force`:

```
[<unknown>] Prelude Control.Exception> :force _exception
_exception = SomeException
(ErrorCallWithLocation "Prelude.read: no parse" [])
[<unknown>] Prelude Control.Exception>
```
3 changes: 3 additions & 0 deletions post/haskell/crash.your.ghc.1.sum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Summary

This series of blogs is "How to crash your GHC and GHCi".
Loading

0 comments on commit 31eeaa4

Please sign in to comment.