Functional programming is usually classified as difficult. The jargon sounds scary and is creating a barrier to newcomers. This is a shame, since in the essence I would argue that functional programming is easier than object-oriented programming.
In this talk, I’ll outline the fundamentals of functional programming and we will take a look at some common constructs from the perspective of the foundations. Hopefully in the end you will walk away with your toes dipped into the world of functional programming wanting to know more. This talk is aimed for the object-oriented programmer. No prior knowledge about FP is required.
Free Monads are a powerful technique that can separate the representation of programs from the messy details of how they get run.
I'll go into the details of how they work, how to use them for fun and profit in your own code, and demonstrate a live Free Monad-driven tank game.
Supporting code at https://github.com/kenbot/free
Some examples and motivation for creating data structures from nothing but functions - Church Encoding! There's particular detail on how it can make free monads more efficient.
Functional programming is usually classified as difficult. The jargon sounds scary and is creating a barrier to newcomers. This is a shame, since in the essence I would argue that functional programming is easier than object-oriented programming.
In this talk, I’ll outline the fundamentals of functional programming and we will take a look at some common constructs from the perspective of the foundations. Hopefully in the end you will walk away with your toes dipped into the world of functional programming wanting to know more. This talk is aimed for the object-oriented programmer. No prior knowledge about FP is required.
Free Monads are a powerful technique that can separate the representation of programs from the messy details of how they get run.
I'll go into the details of how they work, how to use them for fun and profit in your own code, and demonstrate a live Free Monad-driven tank game.
Supporting code at https://github.com/kenbot/free
Some examples and motivation for creating data structures from nothing but functions - Church Encoding! There's particular detail on how it can make free monads more efficient.
Fields in cryptography; covers all important terms used to understand fields including closure, associativity, commutativity, distributivity, identity, inverse, non zero divisors. Each property of field is explained in detail. The same topic field is part of other engineering subjects viz Discrete Structure and Graph Theory. Related topics Groups and Rings are important part of Gate Exam year.
Fields in cryptography; covers all important terms used to understand fields including closure, associativity, commutativity, distributivity, identity, inverse, non zero divisors. Each property of field is explained in detail. The same topic field is part of other engineering subjects viz Discrete Structure and Graph Theory. Related topics Groups and Rings are important part of Gate Exam year.
{- Do not change the skeleton code! The point of this assign.pdfatul2867
{-
Do not change the skeleton code! The point of this
assignment is to figure out how the functions can
be written this way (using fold). You may only
replace the `error "TBD:..."` parts.
For this assignment, you may use the following library functions:
map
foldl'
foldr
length
append (or ++)
zip
-}
module Warmup where
import Prelude hiding (replicate, sum, reverse)
import Data.List (foldl')
foldLeft :: (a -> b -> a) -> a -> [b] -> a
foldLeft = foldl'
foldRight :: (b -> a -> a) -> a -> [b] -> a
foldRight = foldr
-- | Sum the elements of a list
--
-- >>> sumList [1, 2, 3, 4]
-- 10
--
-- >>> sumList [1, -2, 3, 5]
-- 7
--
-- >>> sumList [1, 3, 5, 7, 9, 11]
-- 36
sumList :: [Int] -> Int
sumList xs = error "TBD:sumList"
-- | `digitsOfInt n` should return `[]` if `n` is not positive,
-- and otherwise returns the list of digits of `n` in the
-- order in which they appear in `n`.
--
-- >>> digitsOfInt 3124
-- [3, 1, 2, 4]
--
-- >>> digitsOfInt 352663
-- [3, 5, 2, 6, 6, 3]
digitsOfInt :: Int -> [Int]
digitsOfInt 0 = []
digitsOfInt n = error "TBD:digitsOfInt"
-- | `digits n` retruns the list of digits of `n`
--
-- >>> digits 31243
-- [3,1,2,4,3]
--
-- digits (-23422)
-- [2, 3, 4, 2, 2]
digits :: Int -> [Int]
digits n = digitsOfInt (abs n)
-- | From http://mathworld.wolfram.com/AdditivePersistence.html
-- Consider the process of taking a number, adding its digits,
-- then adding the digits of the number derived from it, etc.,
-- until the remaining number has only one digit.
-- The number of additions required to obtain a single digit
-- from a number n is called the additive persistence of n,
-- and the digit obtained is called the digital root of n.
-- For example, the sequence obtained from the starting number
-- 9876 is (9876, 30, 3), so 9876 has
-- an additive persistence of 2 and
-- a digital root of 3.
--
-- NOTE: assume additivePersistence & digitalRoot are only called with positive numbers
-- >>> additivePersistence 9876
-- 2
additivePersistence :: Int -> Int
additivePersistence n = error "TBD"
-- | digitalRoot n is the digit obtained at the end of the sequence
-- computing the additivePersistence
--
-- >>> digitalRoot 9876
-- 3
digitalRoot :: Int -> Int
digitalRoot n = error "TBD"
-- | listReverse [x1,x2,...,xn] returns [xn,...,x2,x1]
--
-- >>> listReverse []
-- []
--
-- >>> listReverse [1,2,3,4]
-- [4,3,2,1]
--
-- >>> listReverse ["i", "want", "to", "ride", "my", "bicycle"]
-- ["bicycle", "my", "ride", "to", "want", "i"]
listReverse :: [a] -> [a]
listReverse xs = error "TBD"
-- | In Haskell, a `String` is a simply a list of `Char`, that is:
--
-- >>> ['h', 'a', 's', 'k', 'e', 'l', 'l']
-- "haskell"
--
-- >>> palindrome "malayalam"
-- True
--
-- >>> palindrome "myxomatosis"
-- False
palindrome :: String -> Bool
palindrome w = error "TBD"
-- | sqSum [x1, ... , xn] should return (x1^2 + ... + xn^2)
--
-- >>> sqSum []
-- 0
--
-- >>> sqSum [1,2,3,4]
-- 30
--
-- >>> sqSum [(-1), (-2), (-3), (-4)]
-- 30
sqSum :: [Int] -> Int
sqSum xs = foldLeft f bas.
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...akaptur
Byterun is a Python interpreter written in Python with Ned Batchelder. It's architected to mirror the structure of CPython (and be more readable, too)! Learn how the interpreter is constructed, how ignorant the Python compiler is, and how you use a 1,500 line switch statement every day.
Student information management system project report ii.pdfKamal Acharya
Our project explains about the student management. This project mainly explains the various actions related to student details. This project shows some ease in adding, editing and deleting the student details. It also provides a less time consuming process for viewing, adding, editing and deleting the marks of the students.
Immunizing Image Classifiers Against Localized Adversary Attacksgerogepatton
This paper addresses the vulnerability of deep learning models, particularly convolutional neural networks
(CNN)s, to adversarial attacks and presents a proactive training technique designed to counter them. We
introduce a novel volumization algorithm, which transforms 2D images into 3D volumetric representations.
When combined with 3D convolution and deep curriculum learning optimization (CLO), itsignificantly improves
the immunity of models against localized universal attacks by up to 40%. We evaluate our proposed approach
using contemporary CNN architectures and the modified Canadian Institute for Advanced Research (CIFAR-10
and CIFAR-100) and ImageNet Large Scale Visual Recognition Challenge (ILSVRC12) datasets, showcasing
accuracy improvements over previous techniques. The results indicate that the combination of the volumetric
input and curriculum learning holds significant promise for mitigating adversarial attacks without necessitating
adversary training.
Cosmetic shop management system project report.pdfKamal Acharya
Buying new cosmetic products is difficult. It can even be scary for those who have sensitive skin and are prone to skin trouble. The information needed to alleviate this problem is on the back of each product, but it's thought to interpret those ingredient lists unless you have a background in chemistry.
Instead of buying and hoping for the best, we can use data science to help us predict which products may be good fits for us. It includes various function programs to do the above mentioned tasks.
Data file handling has been effectively used in the program.
The automated cosmetic shop management system should deal with the automation of general workflow and administration process of the shop. The main processes of the system focus on customer's request where the system is able to search the most appropriate products and deliver it to the customers. It should help the employees to quickly identify the list of cosmetic product that have reached the minimum quantity and also keep a track of expired date for each cosmetic product. It should help the employees to find the rack number in which the product is placed.It is also Faster and more efficient way.
Final project report on grocery store management system..pdfKamal Acharya
In today’s fast-changing business environment, it’s extremely important to be able to respond to client needs in the most effective and timely manner. If your customers wish to see your business online and have instant access to your products or services.
Online Grocery Store is an e-commerce website, which retails various grocery products. This project allows viewing various products available enables registered users to purchase desired products instantly using Paytm, UPI payment processor (Instant Pay) and also can place order by using Cash on Delivery (Pay Later) option. This project provides an easy access to Administrators and Managers to view orders placed using Pay Later and Instant Pay options.
In order to develop an e-commerce website, a number of Technologies must be studied and understood. These include multi-tiered architecture, server and client-side scripting techniques, implementation technologies, programming language (such as PHP, HTML, CSS, JavaScript) and MySQL relational databases. This is a project with the objective to develop a basic website where a consumer is provided with a shopping cart website and also to know about the technologies used to develop such a website.
This document will discuss each of the underlying technologies to create and implement an e- commerce website.
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Dr.Costas Sachpazis
Terzaghi's soil bearing capacity theory, developed by Karl Terzaghi, is a fundamental principle in geotechnical engineering used to determine the bearing capacity of shallow foundations. This theory provides a method to calculate the ultimate bearing capacity of soil, which is the maximum load per unit area that the soil can support without undergoing shear failure. The Calculation HTML Code included.
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERSveerababupersonal22
It consists of cw radar and fmcw radar ,range measurement,if amplifier and fmcw altimeterThe CW radar operates using continuous wave transmission, while the FMCW radar employs frequency-modulated continuous wave technology. Range measurement is a crucial aspect of radar systems, providing information about the distance to a target. The IF amplifier plays a key role in signal processing, amplifying intermediate frequency signals for further analysis. The FMCW altimeter utilizes frequency-modulated continuous wave technology to accurately measure altitude above a reference point.
Saudi Arabia stands as a titan in the global energy landscape, renowned for its abundant oil and gas resources. It's the largest exporter of petroleum and holds some of the world's most significant reserves. Let's delve into the top 10 oil and gas projects shaping Saudi Arabia's energy future in 2024.
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)MdTanvirMahtab2
This presentation is about the working procedure of Shahjalal Fertilizer Company Limited (SFCL). A Govt. owned Company of Bangladesh Chemical Industries Corporation under Ministry of Industries.
2. Luca Belli, Ph.D.
Senior Software Engineer at Twitter Cortex
@__lucab
• studied math a bunch of years
• lived in the area for 3 winters ❄
• moved to sunny California to do Machine Learning
Deck title
About me
X
9. 9
game :: Maybe Deck
game = case addCard 5 0 of -- returns a Maybe Deck
Nothing -> Nothing
Just deck1 -> case addCard 4 deck1 of -- returns a Maybe Deck
Nothing -> Nothing
Just deck2 -> case addCard 3 deck2 of -- returns a Maybe Deck
Nothing -> Nothing
Just deck3 -> addCard 2 deck3 -- returns a Maybe Deck
Haskell Primer
10. 10
game = emptyDeck >>= addFirstCard >>=
addSecondCard >>= addThirdCard
Haskell Primer
15. 15
-- currying is free!
g :: Int -> Int -> Int
g x y = x + y
f :: Int -> Int
f y = y + 1
f = g 1
Haskell Primer
16. 16
g :: Str -> Int
g x = length x
f :: Int -> Int
f x = x + 1
Haskell Primer
17. 17
g :: Str -> Int
g x = length x
f :: Int -> Int
f x = x + 1
h :: Str -> Int
h x = f(g(x)) = f (g x) = (f . g) x
Haskell Primer
18. 18
data Maybe a = Just a | Nothing
Haskell Primer
Represent failure
19. 19
data Maybe a = Just a | Nothing
-- non secure connections are discarded
gMaybe :: Str -> Maybe Int
gMaybe str
| "https" `isPrefixOf` str = Just (length str)
| otherwise = Nothing
Haskell Primer
Variation on g
20. 20
-- can we compose with f now?
gMaybe :: Str -> Maybe Int
f :: Int -> Int
f x = x + 1
Haskell Primer
21. 21
-- let's try to change f
fMaybe :: Maybe Int -> Int
Haskell Primer
Adapting f
22. 22
-- let's try to change f
fMaybe :: Maybe Int -> Int
fMaybe Just x = f x
Haskell Primer
Adapting f
23. 23
-- let's try to change f
fMaybe :: Maybe Int -> Int
fMaybe Just x = f x
fMaybe Nothing = ??? -- 0? Infinity?
Haskell Primer
Adapting f
24. 24
-- f :: Int -> Int
fMaybe :: Maybe Int -> Maybe Int
fMaybe Just x = Just (f x)
fMaybe Nothing = Nothing
Haskell Primer
36. 36
class Functor F where
map :: (a -> b) -> F a -> F b
Haskell Primer
Abstracting the pattern
37. 37
class Functor F where
map :: (a -> b) -> (F a -> F b)
Haskell Primer
Abstracting the pattern
38. 38
-- map :: (a -> b) -> F a -> F b
-- map :: (a -> b) -> Maybe a -> Maybe b
Haskell Primer
Abstracting the pattern
39. 39
-- map :: (a -> b) -> F a -> F b
-- map :: (a -> b) -> Maybe a -> Maybe b
instance Functor Maybe where
map f Nothing = Nothing
Haskell Primer
Abstracting the pattern
40. 40
-- map :: (a -> b) -> F a -> F b
-- map :: (a -> b) -> Maybe a -> Maybe b
instance Functor Maybe where
map f Nothing = Nothing
map f (Just x) = Just (f x)
Haskell Primer
Abstracting the pattern
41. 41
-- map :: (a -> b) -> F a -> F b
-- map :: (a -> b) -> Maybe a -> Maybe b
instance Functor Maybe where
map f Nothing = Nothing
map f (Just x) = Just (f x)
fMaybe = map f
Haskell Primer
Abstracting the pattern
42. 42
-- map :: (a -> b) -> F a -> F b
-- map :: (a -> b) -> [a] -> [b]
Haskell Primer
Abstracting the pattern
43. 43
-- map :: (a -> b) -> F a -> F b
-- map :: (a -> b) -> [a] -> [b]
instance Functor List where
map _ [] = []
Haskell Primer
Abstracting the pattern
44. 44
-- map :: (a -> b) -> F a -> F b
-- map :: (a -> b) -> [a] -> [b]
instance Functor List where
map _ [] = []
map f x:xs = f x : map xs
Haskell Primer
Abstracting the pattern
45. 45
-- map :: (a -> b) -> F a -> F b
-- map :: (a -> b) -> [a] -> [b]
instance Functor List where
map _ [] = []
map f x:xs = f x : map xs
fList = map f
Haskell Primer
Abstracting the pattern
46. 46
• enhanced type lift functions
• composition is possible via
map f
Recap
47. 47
type Deck = Int
type Card = Int
Monads
Let’s play a game
48. 48
type Deck = Int
type Card = Int
addCard :: Card -> Deck -> Deck
Let’s play a game
Monads
49. 49
type Deck = Int
type Card = Int
addCard :: Card -> Deck -> Deck
addCard c d = c + d
Let’s play a game
Monads
52. 52
-- what happens if we add more?
addCard 2 (addCard 3 (addCard 4 (addCard
5 0 )))
Haskell Primer
The whole game
53. 53
addCard :: Card -> Deck -> Maybe Deck
addCard c d
| c + d < 10 = Just (c + d)
| otherwise = Nothing -- you lose
Let’s make the game more interesting
Monads
56. 56
game :: Maybe Deck
game = case addCard 5 0 of -- returns a Maybe Deck
Nothing -> Nothing
Just deck1 -> case addCard 4 deck1 of -- returns a Maybe Deck
Nothing -> Nothing
Just deck2 -> case addCard 3 deck2 of -- returns a Maybe Deck
Nothing -> Nothing
Just deck3 -> addCard 2 deck3 -- returns a Maybe Deck
Monads
67. 67
(>>=) :: Maybe a ->
(a -> Maybe b)
-> Maybe b
instance Monad Maybe where
return x = Just x
Monads
68. 68
(>>=) :: Maybe a ->
(a -> Maybe b)
-> Maybe b
instance Monad Maybe where
return x = Just x
Nothing >>= _ = Nothing
Monads
69. 69
(>>=) :: Maybe a ->
(a -> Maybe b)
-> Maybe b
instance Monad Maybe where
return x = Just x
Nothing >>= _ = Nothing
(Just x) >>= f = f x
Monads
70. 70
(>>=) :: [a] -> (a -> [b]) -> [b]
What about Lists?
Monads
71. 71
(>>=) :: [a] -> (a -> [b]) -> [b]
(>>=) = flatMap
Haskell Primer
What about Lists?
72. 72
(>>=) :: [a] -> (a -> [b]) -> [b]
(>>=) = flatMap
instance Monad List where
return x = [x]
Haskell Primer
What about Lists?
73. 73
(>>=) :: [a] -> (a -> [b]) -> [b]
(>>=) = flatMap
instance Monad List where
return x = [x]
xs >>= f = concat (map f xs)
Haskell Primer
What about Lists?
74. 74
g :: a -> Maybe b
f :: b -> Maybe c
Recap
Recap
75. 75
g :: a -> Maybe b
f :: b -> Maybe c
(>>=) :: m b -> (b -> m c) -> m c
extracts the b in the output of g and feeds it
to f
Recap
Recap