Created
April 23, 2019 14:25
-
-
Save lnikon/a705c454f7f01c3a1824961b41da4416 to your computer and use it in GitHub Desktop.
learning_haskell1
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
module Lib | |
( someFunc | |
) where | |
someFunc :: IO () | |
someFunc = putStrLn "someFunc" | |
lucky :: (Integral a) => a -> String | |
lucky 7 = "Lucky NUMBER Se7e" | |
lucky x = "Sorry, you're out of luck, pal!" | |
data Expr = Var String | |
| Lit Integer | |
| Expr :+: Expr | |
| Expr :-: Expr | |
| Expr :*: Expr deriving (Show, Eq) | |
factorial :: (Integral a) => a -> a | |
factorial 0 = 1 | |
factorial n = n * factorial(n - 1) | |
addVectors :: (Num a) => (a, a) -> (a, a) -> (a, a) | |
addVectors (x1, y1) (x2, y2) = (x1 + x2, y1 + y2) | |
first :: (a, b, c) -> a | |
first (x, _, _) = x | |
second :: (a, b, c) -> b | |
second (_, y, _) = y | |
third :: (a, b, c) -> c | |
third (_, _, z) = z | |
head' :: [a] -> a | |
head' [] = error "Can't call head on an empty list, dummy!" | |
head' (x:_) = x | |
firstTwo' :: [a] -> (a, a) | |
firstTwo' (x:y:_) = (x, y) | |
firstTwo' [] = error "Can't call firstTwo' on this list, dummy!" | |
firstThree' :: [a] -> (a, a, a) | |
firstThree' (x:y:z:_) = (x, y, z) | |
firstThree' [] = error "Can't call firstThree' on this list, dummy!" | |
length' :: (Num b) => [a] -> b | |
length' [] = 0 | |
length' (_:xs) = 1 + length' xs | |
doBinary :: (Eq a, Ord a) => [a] -> Int | |
doBinary [] = error "Can't search on an empty list" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment