-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ fix ] Make
traverse
and friends lazy for LazyList
- Loading branch information
Showing
7 changed files
with
51 additions
and
5 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import Data.List.Lazy | ||
|
||
import Debug.Trace | ||
|
||
%default total | ||
|
||
xs : LazyList Nat | ||
xs = iterateN 5 (traceValBy (("xs: " ++) . show) . S) Z | ||
|
||
ys : Maybe (List Nat) | ||
ys = for xs $ \n => if n >= 3 then Nothing else Just (10 * n) | ||
|
||
xs' : LazyList Nat | ||
xs' = iterateN 5 (traceValBy (("xs': " ++) . show) . S) Z | ||
|
||
for' : Monad f => LazyList a -> (a -> f b) -> f $ List b | ||
for' [] _ = pure [] | ||
for' (x::xs) g = pure $ !(g x) :: !(for' xs g) | ||
|
||
ys' : Maybe (List Nat) | ||
ys' = for' xs' $ \n => if n >= 3 then Nothing else Just (10 * n) | ||
|
||
main : IO () | ||
main = do | ||
putStrLn $ show ys | ||
putStrLn $ show ys' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
1/1: Building LazyFor (LazyFor.idr) | ||
Main> xs: 1 | ||
xs: 2 | ||
xs: 3 | ||
Nothing | ||
Main> xs': 1 | ||
xs': 2 | ||
xs': 3 | ||
Nothing | ||
Main> | ||
Bye for now! |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
:exec putStrLn $ show ys | ||
:exec putStrLn $ show ys' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
. ../../../testutils.sh | ||
|
||
idris2 -p contrib LazyFor.idr < input |