projprog/fstfunc.hs
2022-01-03 12:06:30 +01:00

83 lines
2.0 KiB
Haskell
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{-# LANGUAGE ParallelListComp #-}
import Text.Printf
addTwo :: Num a => a -> a
addTwo x = x + 2
threeParam :: Num a => a -> a -> a -> a
threeParam x y z = let w = x+y in w*z
myFirst :: (a,b) -> a
myFirst t = let (x,y)=t in x
okko :: [Int] -> [[Char]]
okko xs = [if x<10 then "OK" else "KO" | x <- xs]
addList :: [Int] -> [Int] -> [Int]
addList xs ys = [x+y | x <- xs, y <- ys]
length2 :: [a] -> Int
length2 xs = last [n | _ <- xs | n <- [2,4..]]
greaterTwo :: [Char] -> Bool
greaterTwo "one" = False
greaterTwo "two" = False
greaterTwo _ = True
divide :: Fractional a => Eq a => a -> a -> a
divide _ 0 = -9999
divide p q = p/q
myand :: Bool -> Bool -> Bool
myand False False = False
myand True False = True
myand False True = True
myand True True = False
myand2 :: Bool -> Bool -> Bool
myand2 False b = b
myand2 True b = not b
compVectOld :: (Double,Double) -> (Double,Double) -> Double
compVectOld u v = ((fst u) + (fst v)) * ((snd u) + (snd v))
compVect :: Real a => (a,a) -> (a,a) -> a
compVect (x,y) (w,z) = (x+y)*(w+z)
myFst :: (a,a,a) -> a
myFst (x,y,z) = x
mySnd :: (a,a,a) -> a
mySnd (x,y,z) = y
myThd :: (a,a,a) -> a
myThd (x,y,z) = z
listPat :: Num a => [(a,a,a)] -> [a]
listPat [] = []
listPat ((x,y,z):s) = (x+y*z):(listPat s)
myHead :: [a] -> a
myHead [] = error "The list is empty !"
myHead (x:_) = x
twoEq :: Eq a => [a] -> [a] -> Bool
twoEq (x:_) (y:_) = (x==y)
twoEq [] [] = True
twoEq _ _ = False
myLength :: PrintfType r => [a] -> r
myLength [] = printf "The list has no elements\n"
myLength [x] = printf "The list has one element\n"
myLength [x,y] = printf "The list has two elements\n"
myLength _ = printf "The list has more than two elements\n"
myLengthShow :: PrintfType r => Show a => [a] -> r
myLengthShow [] = printf "The list has no elements\n"
myLengthShow [x] = printf "The list has one element: %s\n" (show x)
myLengthShow [x,y] = printf "The list has two elements: %s and %s\n" (show x) (show y)
myLengthShow _ = printf "The list has more than two elements\n"