-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Anastasios Valtinos
committed
Oct 23, 2022
1 parent
eb332a5
commit 5e00bab
Showing
2 changed files
with
18 additions
and
1 deletion.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
Haskell Excercises & Code/Chapter27 - Nonstrictness/chapterEx.hs
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 |
---|---|---|
@@ -1,2 +1,19 @@ | ||
{-# LANGUAGE Strict #-} | ||
-- this is an extension to enable strictness | ||
|
||
module ChaptEx where | ||
|
||
data List a = Nil | Cons a (List a) deriving (Show) | ||
|
||
take' n _ | n <= 0 = Nil | ||
take' _ Nil = Nil | ||
take' n (Cons x xs) = (Cons x (take' (n-1) xs)) | ||
|
||
map' _ Nil = Nil | ||
map' f (Cons x xs) = (Cons (f x) (map' f xs)) | ||
|
||
repeat' x = xs | ||
where xs = (Cons x xs) | ||
|
||
main = do | ||
print $ take' 10 $ map' (+1) (repeat' 1) |
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