Skip to content

Commit 3c12a87

Browse files
committed
more
1 parent 47a3079 commit 3c12a87

File tree

5 files changed

+46
-33
lines changed

5 files changed

+46
-33
lines changed

haskell/.vscode/phoityne.log

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
2024-06-15 00:27:00.787216000000 [39436(ThreadId 17)] ERROR APP - start debugging failed. user error (ExecResult not found.) : Left "user error (ExecResult not found.)"
88
2024-06-15 00:30:49.937170000000 [40083(ThreadId 16)] CRITICAL REQUEST - invalid HANDLE. eof.
99
2024-06-15 00:31:21.254897000000 [40466(ThreadId 16)] CRITICAL REQUEST - invalid HANDLE. eof.
10+
2024-06-27 10:15:11.049245000000 [65370(ThreadId 16)] CRITICAL REQUEST - invalid HANDLE. eof.

haskell/app/HelloWorld.hs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{-# LANGUAGE FlexibleInstances, UndecidableInstances, DuplicateRecordFields #-}
2+
3+
module HelloWorld(mainHW) where
4+
5+
import Control.Monad
6+
7+
helloWorlds :: (Num n, Eq n) => n -> IO() -> IO()
8+
helloWorlds 0 _ = return ()
9+
helloWorlds n action = do
10+
action
11+
helloWorlds (n - 1) action
12+
13+
helloWorlds2 :: Int -> IO() -> IO()
14+
helloWorlds2 n action = do
15+
forM_ [1..n] $ \_ -> action
16+
17+
helloWorlds3 :: Int -> IO() -> IO()
18+
helloWorlds3 n action = mapM_ (const action) [1..n]
19+
20+
mainHW :: IO()
21+
mainHW = do
22+
n <- readLn :: IO Int
23+
helloWorlds n $ putStrLn "Hello World"
24+
---also
25+
sequence_ $ replicate n $ putStrLn "Hello World"
26+
-- also
27+
replicateM_ n (putStrLn "Hello World")
28+
-- also
29+
helloWorlds2 n $ putStrLn "Hello World"
30+
-- also
31+
helloWorlds3 n $ putStrLn "Hello World"

haskell/app/ListReplication.hs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module ListReplication (mainLR) where
2+
3+
-- Given a list, repeat each element in the list amount of times.
4+
f :: Int -> [Int] -> [Int]
5+
f n arr = concatMap (replicate n) arr
6+
7+
mainLR:: IO()
8+
mainLR = getContents >>=
9+
mapM_ print. (\(n:arr) -> f n arr). map read. words

haskell/app/Main.hs

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,10 @@
22

33
module Main(main) where
44

5-
import Control.Monad
6-
import Data.Array
7-
import Data.Bits
8-
import Data.List
9-
import Data.List.Split
10-
import Data.Set
11-
import Debug.Trace
12-
import System.Environment
13-
import System.IO
14-
import System.IO.Unsafe
5+
--import HelloWorld(mainHW)
6+
import ListReplication(mainLR)
157

168

17-
helloWorlds :: (Num n, Eq n) => n -> IO() -> IO()
18-
helloWorlds 0 _ = return ()
19-
helloWorlds n action = do
20-
action
21-
helloWorlds (n - 1) action
22-
23-
helloWorlds2 :: Int -> IO() -> IO()
24-
helloWorlds2 n action = do
25-
forM_ [1..n] $ \_ -> action
26-
27-
helloWorlds3 :: Int -> IO() -> IO()
28-
helloWorlds3 n action = mapM_ (const action) [1..n]
29-
309
main :: IO()
3110
main = do
32-
n <- readLn :: IO Int
33-
helloWorlds n $ putStrLn "Hello World"
34-
---also
35-
sequence_ $ replicate n $ putStrLn "Hello World"
36-
-- also
37-
replicateM_ n (putStrLn "Hello World")
38-
-- also
39-
helloWorlds2 n $ putStrLn "Hello World"
40-
-- also
41-
helloWorlds3 n $ putStrLn "Hello World"
11+
mainLR

haskell/voidhask.cabal

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ executable voidhask-exe
4747
other-modules:
4848
Fun
4949
Functions
50+
HelloWorld
51+
ListReplication
5052
Main01
5153
MtlEx
5254
Paths_voidhask

0 commit comments

Comments
 (0)