on master help sign in
Rollback on laziness for now.
80e8af6Evan Czaplicki
libraries/Lazy.elmdeleted−53
@@ -1,53 +0,0 @@
1−module Lazy ( force, lazy, map, apply, bind
2− ) where
3−
4−{-| Library for efficient Lazy evaluation.
5−
6−# Delay
7−@docs lazy
8−
9−# Evaluate
10−@docs force
11−
12−# Transform
13−@docs map, apply, bind
14−-}
15−
16−import Basics ((<|), (.))
17−import Native.Lazy
18−
19−data Lazy a = L { force : () -> a }
20−
21−{-| Delay a computation. This function memoizes results, so
22−it guarantees that the computation will be evaluated at most once.
23−-}
24−lazy : (() -> a) -> Lazy a
25−lazy t = L { force = (Native.Lazy.lazy t) }
26−
27−{-| Evaluate a lazy value. It saves the result so the second time
28−you call `force` it does not run the computation again. -}
29−force : Lazy a -> a
30−force (L r) = r.force ()
31−
32−{-| Lazily apply a function to a lazy value. The computation
33−will be delayed until you force the resulting value.
34−-}
35−map : (a -> b) -> Lazy a -> Lazy b
36−map f t = lazy <| \() ->
37− f . force <| t
38−
39−{-| Lazily apply a lazy function to a lazy value. This can
40−be used to lazily apply a function to many arguments:
41−
42−```haskell
43−f `map` a `apply` b `apply` c
44−```
45−-}
46−apply : Lazy (a -> b) -> Lazy a -> Lazy b
47−apply f x = lazy <| \() ->
48− (force f) (force x)
49−
50−{-| Lazily chain together lazy computations. -}
51−bind : Lazy a -> (a -> Lazy b) -> Lazy b
52−bind x k = lazy <| \() ->
53− force . k . force <| x
libraries/Lazy/Stream.elmdeleted−275
@@ -1,275 +0,0 @@
1−module Lazy.Stream ( head, tail
2− , cons, cons', iterate, repeat, cycle
3− , map, apply, zip, zipWith, scanl
4− , take, drop, splitAt
5− , sampleOn
6− , filter, takeWhile, dropWhile, splitWith
7− ) where
8−
9−{-| This library is for creating and manipulating infinite streams
10−
11−# Create
12−@docs cons, cons', repeat, cycle, iterate
13−
14−# Use
15−@docs head, tail, sampleOn, take, takeWhile, drop, dropWhile, splitAt, splitWith
16−
17−# Transform
18−@docs map, zip, zipWith, scanl, filter, apply
19−
20−-}
21−
22−import Basics ((.), (<|), (-), id, fst, snd)
23−import open Lazy
24−import Signal ((<~), foldp, Signal)
25−
26−data Stream a = S (Lazy (a, Stream a))
27−
28−unS : Stream a -> (a, Stream a)
29−unS (S t) = force t
30−
31−{-| Get the first element of a stream, called the `head`.
32−
33−```haskell
34−head ones == 1
35−```
36−-}
37−head : Stream a -> a
38−head = fst . unS
39−
40−{-| Drop the `head` of a stream, leaving you with the `tail`.
41−
42−```haskell
43−-- 1, 1, 1, 1, ...
44−stillAllOnes = tail
45−```
46−-}
47−tail : Stream a -> Stream a
48−tail = snd . unS
49−
50−{-| Create a stream:
51−
52−```haskell
53−-- 1, 1, 1, 1, ...
54−ones = cons 1 (\() -> ones)
55−```
56− -}
57−cons : a -> (() -> Stream a) -> Stream a
58−cons x txs = let mtxs = lazy txs in
59− S . lazy <| \() ->
60− (x, force mtxs)
61−
62−{-| Create a stream that is slightly more lazy. Notice that the
63−head of the stream is defined within the thunk, so its evaluation
64−is delayed. This is nice when each element of the stream is costly to compute.
65−
66−```haskell
67−-- 1, 1, 1, 1, ...
68−ones = cons' (\_ -> (1,ones))
69−```
70−-}
71−cons' : (() -> (a, Stream a)) -> Stream a
72−cons' = S . lazy
73−
74−{-| Iteratively apply a function to a value:
75−
76−```haskell
77−-- x, f x, f (f x), f (f (f x)), ...
78−iterate f x
79−
80−-- 2, 4, 8, 16, ...
81−powersOf2 = iterate (\n -> n^2) 2
82−```
83−-}
84−iterate : (a -> a) -> a -> Stream a
85−iterate f x =
86− cons' <| \_ -> (x, iterate f (f x))
87−
88−{-| Repeat a value infinitely:
89−
90−```haskell
91−-- 1, 1, 1, 1, ...
92−ones = repeat 1
93−```
94− -}
95−repeat : a -> Stream a
96−repeat x = let go = cons x <| \() -> go
97− in go
98−
99−{-| Infinitely cycle through a list, where the head and tail of
100−the list are given separately to ensure that no one tries to cycle
101−on an empty list:
102−
103−```haskell
104−-- "Alice", "Bob", "Alice", "Bob", ...
105−cycle "Alice" ["Bob"]
106−```
107−-}
108−cycle : a -> [a] -> Stream a
109−cycle x xs =
110− let cycle' ys = case ys of
111− [] -> go
112− (y :: ys) -> cons y (\_ -> cycle' ys)
113− go = cons' <| \_ -> (x, cycle' xs)
114− in go
115−
116−{-| Apply a function to every element of a Stream.
117−
118−```haskell
119−-- 2, 2, 2, 2, ...
120−twos = map (\n -> n + 1) ones
121−```
122−-}
123−map : (a -> b) -> Stream a -> Stream b
124−map f xs =
125− cons' <| \_ -> (f (head xs), map f (tail xs))
126−
127−{-| Pairwise apply a stream of functions to a stream of arguments.
128−When paired with `map`, this can be used to emulate `zipWith` over *n* streams.
129−
130−```haskell
131−zipWith3 : (a -> b -> c -> d) -> Stream a -> Stream b -> Stream c -> Stream d
132−zipWith3 f xs ys zs = f `S.map` xs `S.apply` ys `S.apply` zs
133−```
134−-}
135−apply : Stream (a -> b) -> Stream a -> Stream b
136−apply fs xs = zipWith (<|) fs xs
137−
138−{-| Combine two streams, putting them into tuples pairwise:
139−
140−```haskell
141−-- (1,2), (1,4), (1,8), (1,16), ...
142−pairs = zip ones powersOf2
143−```
144−-}
145−zip : Stream a -> Stream b -> Stream (a,b)
146−zip = zipWith (\x y -> (x,y))
147−
148−{-| Combine two streams, applying the given function pairwise:
149−
150−```haskell
151−-- 3, 5, 9, 17, ...
152−zipWith (+) ones powersOf2
153−```
154−-}
155−zipWith : (a -> b -> c) -> Stream a -> Stream b -> Stream c
156−zipWith f xs ys = cons' <| \() ->
157− (f (head xs) (head ys),
158− zipWith f (tail xs) (tail ys))
159−
160−{-| Scan over a stream from the left, building an infinite stream of reductions.
161−
162−```haskell
163−-- 0, 1, 2, 3, ...
164−runningTotal = scanl (+) 0 ones
165−```
166−-}
167−scanl : (a -> b -> b) -> b -> Stream a -> Stream b
168−scanl f init xs =
169− cons' <| \() -> (init, scanl f (f (head xs) init) (tail xs))
170−
171−{-| Take the first *n* elements of a stream
172−
173−```haskell
174−take 5 powersOf2 == [2,4,8,16,32]
175−```
176−-}
177−take : Int -> Stream a -> [a]
178−take n xs = fst <| splitAt n xs
179−
180−{-| Drop the first *n* elements of a stream
181−
182−```haskell
183−-- 64, 128, 256, 512, ...
184−drop 5 powersOf2
185−```
186−-}
187−drop : Int -> Stream a -> Stream a
188−drop n xs = snd <| splitAt n xs
189−
190−{-| Combination of `take` and `drop`
191−
192−```haskell
193−splitAt n xs == (take n xs, drop n xs)
194−```
195−-}
196−splitAt : Int -> Stream a -> ([a], Stream a)
197−splitAt n xs = case n of
198− 0 -> ([], xs)
199− n -> let (heads, end) = splitAt (n - 1) (tail xs)
200− in (head xs :: heads, end)
201−
202−{-| Turn a stream into a signal of the elements of the stream,
203−advancing through the stream whenever an event in the given signal is
204−fired.
205−-}
206−sampleOn : Signal b -> Stream a -> Signal a
207−sampleOn sig str = let tails = foldp (\_ -> tail) str sig in
208− head <~ tails
209−
210−{-| Filter the elements of a Stream according to a predicate.
211−
212−```haskell
213−-- 1, 3, 5, 7, ...
214−filter isOdd naturals
215−
216−-- Bad! Infinite loop!
217−filter isOdd twos
218−```
219−
220−This can infinite loop if no more elements in the stream satisfy the predicate!
221−-}
222−filter : (a -> Bool) -> Stream a -> Stream a
223−filter pred xs = cons' <| (\() ->
224− let (hd, tl) = unS xs in
225− case pred hd of
226− True -> (hd, filter pred tl)
227− False -> unS <| filter pred tl)
228−
229−{-| Take values from the stream for as long as the predicate holds.
230−This can infinite loop if all elements of the stream satisfy the predicate!
231−
232−```haskell
233−takeWhile (\n -> n < 10) powersOf2 == [2,4,8]
234−
235−-- Bad! Infinite loop!
236−takeWhile isEven powersOf2
237−```
238−
239−This can infinite loop if all elements of the stream satisfy the predicate!
240−-}
241−takeWhile : (a -> Bool) -> Stream a -> [a]
242−takeWhile pred xs = fst <| splitWith pred xs
243−
244−{-| Drop values from the stream as long as the predicate holds.
245−
246−```haskell
247−-- 16, 32, 64, 128, ...
248−dropWhile (\n -> n < 10) powersOf2
249−
250−-- Bad! Infinite loop!
251−dropWhile isEven powersOf2
252−```
253−
254−This can infinite loop if all elements of the stream satisfy the predicate!
255−-}
256−dropWhile : (a -> Bool) -> Stream a -> Stream a
257−dropWhile pred xs = snd <| splitWith pred xs
258−
259−{-| Combination of `takeWhile` and `dropWhile`. Split a stream when
260−the predicate no longer holds.
261−
262−```haskell
263−splitWith pred xs == (takeWhile pred xs, dropWhile pred xs)
264−
265−splitWith (\n -> n < 10) powersOf2 == ([2,4,8], ...)
266−```
267−
268−This can infinite loop if all elements satisfy the predicate!
269−-}
270−splitWith : (a -> Bool) -> Stream a -> ([a], Stream a)
271−splitWith pred xs = let (hd, tl) = unS xs in
272− case pred hd of
273− True -> let (taken, dropped) = splitWith pred tl
274− in (hd :: taken, dropped)
275− False -> ([], xs)
libraries/Native/Lazy.jsdeleted−26
@@ -1,26 +0,0 @@
1−Elm.Native.Lazy = {};
2−Elm.Native.Lazy.make = function(elm) {
3− elm.Native = elm.Native || {};
4− elm.Native.Lazy = elm.Native.Lazy || {};
5−
6− if (elm.Native.Lazy.values) return elm.Native.Lazy.values;
7−
8− var Utils = Elm.Native.Utils.make(elm);
9−
10− function lazy(f) {
11− var value = {};
12− var isEvaled = false;
13− var memoed = function(x) {
14− if(!isEvaled) {
15− value = f(Utils.Tuple0);
16− isEvaled = true;
17− }
18− return value;
19− }
20− return memoed;
21− }
22−
23− return elm.Native.Lazy.values = {
24− lazy : lazy
25− };
26−};