Nested strict data in Haskell Introduction Every so often someone bemoans the space leaks that can arise due to Haskell’s laziness. A frequently touted remedy is to make data stricter by turning on BangPatterns, by defining data structures with explicitly strict fields, or by creating implicitly strict fields with the StrictData extension. Each of these approaches leaves something to be desired. I
Haskellがとっつきにくい原因の一つに遅延評価がある。入門書では、無限リストと遅延評価がことさら強調される。しかし、Haskellを業務で使ってみると、遅延評価が煩わしくなってくる。遅延評価なしでもほとんどのことは実現できるし、メモリーの使用量は推測できないし、あまりいいことはない。 Haskellの評価戦略が、他の言語と同じように正格評価だったらよかったのに。 今まで、このようなセリフを何度聞いたか分からない。 そもそも遅延評価が役立つことはあるのだろうか? ある。お世辞抜きに、少なくとも以下の3つでは本当に役立つ。 リスト(あるいは類似のデータ構造)処理 純粋性に対する暗黙のテスト 効率的なCAS 1.はよいだろう。2.は純粋さを守るために必要だが、コンパイラを開発する人にとって重要なのであり、ユーザには関係ない。3.は、並行プログラミングの奥義である。atomicModifyIO
All About Strictness Analysis (part 1) December 4, 2017 Non-strict languages like Haskell often require the programmer to reason about strictness to achieve good performance. A while ago, Michael Snoyman wrote a blog post about this, giving an introduction on the matter as well as an overview over the tools at our disposal. In this post, I want to offer another, more surgical approach to plugging
I was recently trying to optimize Dhall's performance because the interpreter was performing poorly on some simple examples. For example, consider this tiny expression that prints 3000 exclamation marks: The above Dhall expression takes over 14 seconds to evaluate to normal form, which is not acceptable: $ bench 'dhall <<< './exclaim' benchmarking dhall <<< ./exclaim time 14.42 s (14.23 s .. 14.57
Haskell is—perhaps infamously—a lazy language. The basic idea of laziness is pretty easy to sum up in one sentence: values are only computed when they’re needed. But the implications of this are more subtle. In particular, it’s important to understand some crucial topics if you want to write memory- and time-efficient code: Weak head normal form (WHNF) versus normal form (NF) How to use the seq an
Reflecting strictness in Haskell types In GHC, from the operational point of view, the type Int does not indicate a bit pattern somewhere in memory that represents an integer. What it indicates is either an integer bit pattern or a “thunk” (a delayed computation) which can be “forced” (run). When and if the computation terminates the thunk will be overwritten with the integer bit pattern that it p
λ. 正格性解析 (Strictness Analysis) この記事はHaskell Advent Calendarのために書かれたものです。(22日目) 正格性解析(strictness analysis)は、Haskellのような遅延評価を行う純粋関数型言語での最も基本的な最適化のひとつの割に、あまり知られていないようなので、簡単に紹介してみることに。 動機 よくある例だけど、末尾再帰で書かれた sum' :: Int → [Int] → Int sum' s [] = s sum' s (x:xs) = sum' (s+x) xs というプログラムは、Haskellでは最適化が行われない限り悲惨なことになる。 sum' 0 [1,2,3,4] を計算すると、sum' 0 [1,2,3] ⇒ sum' (0+1) [2,3] ⇒ sum' ((0+1)+2) [3] ⇒ sum' (
Masahiro Sakai @masahiro_sakai 日記更新 正格性解析 (Strictness Analysis): この記事はHaskell Advent Calendarのために書かれたものです。(22日目) 正格性解析(strictness analysis)は、Ha... http://bit.ly/fEJ1xh 2010-12-29 02:36:41 Ikegami Daisuke @ikegami__ つぎは僕の番で、point-free style を紹介しようと思ったんだけど、「sum = foldl (+) の最適化は、正格性解析に関してはむずかしい」ということが書いてあって、そのとおりなんですが、point-free よくないやんけ、ということではないので書かないとうう 2010-12-29 05:23:42
Is Haskell's laziness actually a Good Thing? In writing code to process large data sets in Haskell I've come across more instances where laziness has been harmful than instances when it is beneficial. When everything needs processing and all calculations will be used, laziness just means that programs take up extortionate amounts of heap space while they delay all computation until the last minute
Background This question arises from a challenge Brent Yorgey posed at OPLSS: write a function f :: (Int -> Int) -> Bool that distinguishes f undefined from f (\x -> undefined). All of our answers either used seq or something like bang patterns that desugar into seq. For example: f :: (Int -> Int) -> Bool f g = g `seq` True *Main> f undefined *** Exception: Prelude.undefined *Main> f (\x -> undefi
What does Weak Head Normal Form (WHNF) mean? What does Head Normal form (HNF) and Normal Form (NF) mean? Real World Haskell states: The familiar seq function evaluates an expression to what we call head normal form (abbreviated HNF). It stops once it reaches the outermost constructor (the "head"). This is distinct from normal form (NF), in which an expression is completely evaluated. You will also
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く