forked from Kaleb47/Haskell-Plutus-journal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
curriedpartiallyapplied.hs
33 lines (25 loc) · 1.08 KB
/
curriedpartiallyapplied.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import Data.List (nub, sort, transpose, inits, tails) --you can selectively import functions
{-import Data.List hiding (nub) you're importing all functions accept the nub-}
-- import qualified Data.Map as M
-- Now, to reference Data.Map's filter function, we just use M.filter
import qualified Data.Map as M
import qualified Data.Set
import qualified Data.Char as Char --qualified imports need as, so call data.Char
numUniques :: (Eq a) => [a] -> Int
numUniques = length . nub
search :: (Eq a) => [a] -> [a] -> Bool
search needle haystack =
let nlen = length needle
in foldl (\acc x -> if take nlen x == needle then True else acc) False (tails haystack)
--Haskells version of Caesar's cipher
encode :: Int -> String -> String
encode shift msg =
let ords = map ord msg
shifted = map (+ shift) ords
in map chr shifted
ord :: Char -> b
ord = error "not implemented"
chr :: Int -> Char
chr = error "not implemented"
findKey :: (Eq k) => k -> [(k,v)] -> Maybe v
findKey key = foldr (\(k,v) acc -> if key == k then Just v else acc) Nothing