Skip to content
This repository was archived by the owner on Jul 24, 2023. It is now read-only.

Commit 5151c50

Browse files
author
cd155
committed
interview quick note
1 parent 0ce2831 commit 5151c50

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

QuickNote.hs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{-
2+
Quick note for writing Haskell
3+
-}
4+
5+
6+
-- add module
7+
module QuickNote where
8+
9+
-- create a synonym
10+
type Nat = Int
11+
12+
-- declaration
13+
mergeSort :: Ord a => [a] -> [a]
14+
15+
-- patten match
16+
mergeSort [] = []
17+
mergeSort [x] = [x]
18+
mergeSort xs = merge (mergeSort firstHalf) (mergeSort secondHalf)
19+
20+
-- where cause
21+
where (firstHalf, secondHalf) = splitAt (length xs `div` 2) xs
22+
23+
merge :: Ord a => [a] -> [a] -> [a]
24+
merge [] ys = ys
25+
merge xs [] = xs
26+
27+
-- pattern match for list
28+
merge (x:xs) (y:ys)
29+
30+
-- condition statement
31+
| x <= y = x : merge xs (y:ys)
32+
| otherwise = y : merge (x:xs) ys
33+
34+
-- initialize a list
35+
smArrX = [1, 4, 10, 100, 1000]
36+
37+
-- ADT (abstract data type) for binary tree
38+
data BiTree a = Null | Node a (BiTree a) (BiTree a) deriving Show

0 commit comments

Comments
 (0)