This document discusses Functor, Applicative Functor, Foldable and Traversable type classes in Haskell. It provides examples of using fmap, pure, (<*>), foldMap, traverse and sequenceA for different types like Maybe, lists and IO. It shows how Foldable is about folding while Traversable allows transforming elements of a structure with an Applicative. Traverse is used to define sequenceA and allows rejecting elements with negatives from a list.
This presentation takes you on a functional programming journey, it starts from basic Scala programming language design concepts and leads to a concept of Monads, how some of them designed in Scala and what is the purpose of them
Zippers are a design pattern in functional programming languages, such as Haskell, which provides a focus point and methods for navigating around in a functional data structure. It turns out that for any algebraic data type with one parameter, the derivative of the type is a zipper for it.
Beginning Haskell, Dive In, Its Not That Scary!priort
Haskell can get a bit of a reputation for being this lofty, academic, difficult to learn language. This talk aims to dispel this myth and offer an introduction to this beautiful and pragmatic language. From the point of view of someone who has been functional programming in Scala and Clojure for a while now, but who has, more recently been taking a dive into Haskell, this talk will give a basic introduction to Haskell. Hopefully it will encourage anyone who hasn't tried functional programming in Haskell to dive in too and give it a go.
The talk will be a whistle stop tour of some functional programming fundamentals in Haskell from basic data structures, logic constructs, functional transformations, recursion to some of the basics of Haskell's type system with data declarations and type classes.
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.
This presentation takes you on a functional programming journey, it starts from basic Scala programming language design concepts and leads to a concept of Monads, how some of them designed in Scala and what is the purpose of them
Zippers are a design pattern in functional programming languages, such as Haskell, which provides a focus point and methods for navigating around in a functional data structure. It turns out that for any algebraic data type with one parameter, the derivative of the type is a zipper for it.
Beginning Haskell, Dive In, Its Not That Scary!priort
Haskell can get a bit of a reputation for being this lofty, academic, difficult to learn language. This talk aims to dispel this myth and offer an introduction to this beautiful and pragmatic language. From the point of view of someone who has been functional programming in Scala and Clojure for a while now, but who has, more recently been taking a dive into Haskell, this talk will give a basic introduction to Haskell. Hopefully it will encourage anyone who hasn't tried functional programming in Haskell to dive in too and give it a go.
The talk will be a whistle stop tour of some functional programming fundamentals in Haskell from basic data structures, logic constructs, functional transformations, recursion to some of the basics of Haskell's type system with data declarations and type classes.
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.
AdRoll Tech Talk Presentation:
In this talk I present three approaches to understanding monads:
- How Monads Arise Naturally
- Monads as Implemented in Haskell
- Monads in Category Theory
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
Stanfy MadCode Meetup #9: Functional Programming 101 with SwiftStanfy
This time Alexander Voronov (@aleks_voronov), iOS Developer at Stanfy talked about Functional Programming 101 with Swift
Key points:
- Why do we need Functional Programming?
- The power of Swift
- Functors, Applicatives and Monads
- Pipes & Railways
- Functional Swift in real life
Links Mentioned:
- Functors, Applicatives and Monads in Pictures: http://adit.io/posts/2013-04-17-funct...
- Railway Oriented Programming: http://fsharpforfunandprofit.com/post...
- Functional Programming in Swift (Objc.io): http://www.objc.io/books/fpinswift/
- Moya: https://github.com/Moya/Moya
- Argo: https://github.com/thoughtbot/Argo
- Swiftz: https://github.com/typelift/Swiftz
- RxSwift: https://github.com/ReactiveX/RxSwift
- ReactiveCocoa-3.0: https://github.com/ReactiveCocoa/Reac...
- Haskell: https://www.haskell.org
- F#: http://fsharp.org
- Erlang: http://www.erlang.org
- Elm: http://elm-lang.org
Watch video from the presentation (rus): https://youtu.be/w6zyGylS4Wk
Join our MadCode group on FB(rus): https://www.facebook.com/MadCodeMeetup/
Find more videos from MadCode Meetups (rus): https://www.youtube.com/playlist?list=PLrplqd3YJvBvUygFkx4Xvx1p3zyiCgB9Q
Kickstart your data science journey with this Python cheat sheet that contains code examples for strings, lists, importing libraries and NumPy arrays.
Find more cheat sheets and learn data science with Python at www.datacamp.com.
Functional Patterns for the non-mathematicianBrian Lonsdorf
Fluentconf 2014 talk:
Functional design patterns such as lenses, arrows, functors, and monads all come from category theory. To fully grok them, you’ll probably have to wade through the whitest white papers, fighting the mathematical syntax and abstract examples.
I’m hoping to demonstrate the ideas into javascript. I’ll be showing direct and practical applications for every day programming.
AdRoll Tech Talk Presentation:
In this talk I present three approaches to understanding monads:
- How Monads Arise Naturally
- Monads as Implemented in Haskell
- Monads in Category Theory
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
Stanfy MadCode Meetup #9: Functional Programming 101 with SwiftStanfy
This time Alexander Voronov (@aleks_voronov), iOS Developer at Stanfy talked about Functional Programming 101 with Swift
Key points:
- Why do we need Functional Programming?
- The power of Swift
- Functors, Applicatives and Monads
- Pipes & Railways
- Functional Swift in real life
Links Mentioned:
- Functors, Applicatives and Monads in Pictures: http://adit.io/posts/2013-04-17-funct...
- Railway Oriented Programming: http://fsharpforfunandprofit.com/post...
- Functional Programming in Swift (Objc.io): http://www.objc.io/books/fpinswift/
- Moya: https://github.com/Moya/Moya
- Argo: https://github.com/thoughtbot/Argo
- Swiftz: https://github.com/typelift/Swiftz
- RxSwift: https://github.com/ReactiveX/RxSwift
- ReactiveCocoa-3.0: https://github.com/ReactiveCocoa/Reac...
- Haskell: https://www.haskell.org
- F#: http://fsharp.org
- Erlang: http://www.erlang.org
- Elm: http://elm-lang.org
Watch video from the presentation (rus): https://youtu.be/w6zyGylS4Wk
Join our MadCode group on FB(rus): https://www.facebook.com/MadCodeMeetup/
Find more videos from MadCode Meetups (rus): https://www.youtube.com/playlist?list=PLrplqd3YJvBvUygFkx4Xvx1p3zyiCgB9Q
Kickstart your data science journey with this Python cheat sheet that contains code examples for strings, lists, importing libraries and NumPy arrays.
Find more cheat sheets and learn data science with Python at www.datacamp.com.
Functional Patterns for the non-mathematicianBrian Lonsdorf
Fluentconf 2014 talk:
Functional design patterns such as lenses, arrows, functors, and monads all come from category theory. To fully grok them, you’ll probably have to wade through the whitest white papers, fighting the mathematical syntax and abstract examples.
I’m hoping to demonstrate the ideas into javascript. I’ll be showing direct and practical applications for every day programming.
Function Programming in Scala.
A lot of my examples here comes from the book
Functional programming in Scala By Paul Chiusano and Rúnar Bjarnason, It is a good book, buy it.
Using the work of Dr. Graham Hutton as our guide, we'll look at how to satisfy all of your list processing needs with one function, fold. First we'll start off simple by finding the length of a list, then we'll reverse a list, followed by and-ing and or-ing a list; all using fold. Next we'll look at implementing the higher order functions of: map, filter, and zip. Last we'll look at fold in action by using it on the Coin Changer kata. You'll never look at fold the same way again.
Function Programming in Scala.
A lot of my examples here comes from the book
Functional programming in Scala By Paul Chiusano and Rúnar Bjarnason, It is a good book, buy it.
Welcome to WIPAC Monthly the magazine brought to you by the LinkedIn Group Water Industry Process Automation & Control.
In this month's edition, along with this month's industry news to celebrate the 13 years since the group was created we have articles including
A case study of the used of Advanced Process Control at the Wastewater Treatment works at Lleida in Spain
A look back on an article on smart wastewater networks in order to see how the industry has measured up in the interim around the adoption of Digital Transformation in the Water Industry.
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.
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.
Forklift Classes Overview by Intella PartsIntella Parts
Discover the different forklift classes and their specific applications. Learn how to choose the right forklift for your needs to ensure safety, efficiency, and compliance in your operations.
For more technical information, visit our website https://intellaparts.com
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.
6th International Conference on Machine Learning & Applications (CMLA 2024)ClaraZara1
6th International Conference on Machine Learning & Applications (CMLA 2024) will provide an excellent international forum for sharing knowledge and results in theory, methodology and applications of on Machine Learning & Applications.
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.
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.
HEAP SORT ILLUSTRATED WITH HEAPIFY, BUILD HEAP FOR DYNAMIC ARRAYS.
Heap sort is a comparison-based sorting technique based on Binary Heap data structure. It is similar to the selection sort where we first find the minimum element and place the minimum element at the beginning. Repeat the same process for the remaining elements.
Water billing management system project report.pdfKamal Acharya
Our project entitled “Water Billing Management System” aims is to generate Water bill with all the charges and penalty. Manual system that is employed is extremely laborious and quite inadequate. It only makes the process more difficult and hard.
The aim of our project is to develop a system that is meant to partially computerize the work performed in the Water Board like generating monthly Water bill, record of consuming unit of water, store record of the customer and previous unpaid record.
We used HTML/PHP as front end and MYSQL as back end for developing our project. HTML is primarily a visual design environment. We can create a android application by designing the form and that make up the user interface. Adding android application code to the form and the objects such as buttons and text boxes on them and adding any required support code in additional modular.
MySQL is free open source database that facilitates the effective management of the databases by connecting them to the software. It is a stable ,reliable and the powerful solution with the advanced features and advantages which are as follows: Data Security.MySQL is free open source database that facilitates the effective management of the databases by connecting them to the software.
Hierarchical Digital Twin of a Naval Power SystemKerry Sado
A hierarchical digital twin of a Naval DC power system has been developed and experimentally verified. Similar to other state-of-the-art digital twins, this technology creates a digital replica of the physical system executed in real-time or faster, which can modify hardware controls. However, its advantage stems from distributing computational efforts by utilizing a hierarchical structure composed of lower-level digital twin blocks and a higher-level system digital twin. Each digital twin block is associated with a physical subsystem of the hardware and communicates with a singular system digital twin, which creates a system-level response. By extracting information from each level of the hierarchy, power system controls of the hardware were reconfigured autonomously. This hierarchical digital twin development offers several advantages over other digital twins, particularly in the field of naval power systems. The hierarchical structure allows for greater computational efficiency and scalability while the ability to autonomously reconfigure hardware controls offers increased flexibility and responsiveness. The hierarchical decomposition and models utilized were well aligned with the physical twin, as indicated by the maximum deviations between the developed digital twin hierarchy and the hardware.
Using recycled concrete aggregates (RCA) for pavements is crucial to achieving sustainability. Implementing RCA for new pavement can minimize carbon footprint, conserve natural resources, reduce harmful emissions, and lower life cycle costs. Compared to natural aggregate (NA), RCA pavement has fewer comprehensive studies and sustainability assessments.
7. Applicative Maybe 예제
> Just (+3) <*> Just 4
Just 7
> pure (+3) <*> Nothing
Nothing
> pure (+) <*> Just 3 <*> Just 4
Just 7
> (*) <$> Just 2 <*> Just 8
Just 16
12. liftA2
• 일반 함수를 두 개의 functor에 쉽게 apply 할 수 있게
해주는 함수
liftA2 :: (Applicative f) =>
(a -> b -> c) ->
f a -> f b -> f c
liftA2 f a b = f <$> a <*> b
13. liftA2 예제
> (+) <$> Just 3 <*> Just 4
Just 7
> liftA2 (+) (Just 3) (Just 4)
Just 7
14. Applicative Functor 법칙
1. pure f <*> x = fmap f x
2. pure id <*> v = v
3. pure (.) <*> u <*> v <*> w = u <*> (v <*> w)
4. pure f <*> pure x = pure (f x)
5. u <*> pure y = pure ($ y) <*> u
20. foldr 다시 보기
• foldr :: (a -> (b -> b)) -> b -> [a] -> b
• b -> b는 composition에 대해 Monoid
• mappend = (.)
• mempty = id
newtype Endo b = Endo { appEndo :: b -> b }
instance Monoid Endo where
mempty = Endo id
Endo g `mappend` Endo f = Endo (g . f)
21. foldComposing
foldComposing :: (a -> (b -> b)) -> [a] -> Endo b
foldComposing f = foldMap (Endo . f)
foldr :: (a -> (b -> b)) -> b -> [a] -> b
foldr f z xs = appEndo (foldComposing f xs) z
• foldr을 foldMap을 이용해 정의할 수 있다는 의미
23. Foldable 타입 클래스
class Foldable t where
foldMap :: Monoid m => (a -> m) -> t a -> m
foldr :: (a -> b -> b) -> b -> t a -> b
• foldMap과 foldr 둘 중 하나만 정의하면 됨
24. Foldable 타입 클래스 함
수
• fold :: Monoid m => t m -> m --
generalised mconcat
• foldr' :: (a -> b -> b) -> b -> t a -
> b
• foldl :: (b -> a -> b) -> b -> t a -
> b
• foldl' :: (b -> a -> b) -> b -> t a -
> b
• foldr1 :: (a -> a -> a) -> t a -> a
• foldl1 :: (a -> a -> a) -> t a -> a
• toList :: t a -> [a]
• null :: t a -> Bool
• length :: t a -> Int
• elem :: Eq a => a -> t a -> Bool
• maximum :: Ord a => t a -> a
• minimum :: Ord a => t a -> a
• sum :: Num a => t a -> a
• product :: Num a => t a -> a
25. Data.Foldable 함수
• traverse_ :: (Foldable t, Applicative f) => (a -> f b) -> t a ->
f ()
• Map each element of a structure to an action, evaluate
these actions from left to right, and ignore the results. For a
version that doesn't ignore the results see traverse.
• mapM_ :: (Foldable t, Monad m) => (a -> m b) -> t a -> m ()
• Map each element of a structure to a monadic action,
evaluate these actions from left to right, and ignore the
results. For a version that doesn't ignore the results see
mapM.
26. Foldable 예제
> import qualified Data.Map as M
> let testMap = M.fromList $ zip [0..] ["Yesterday","I","woke","up","sucking","a","lemon"]
> length testMap
7
> sum . fmap length $ testMap
29
> elem "lemon" testMap
True
> foldr1 (x y -> x ++ (' ' : y)) testMap
"Yesterday I woke up sucking a lemon"
27. Foldable 예제
> import Data.Foldable
> traverse_ putStrLn testMap
Yesterday
I
woke
up
sucking
a
lemon
28. Traversable
deleteIfNegative :: (Num a, Ord a) => a -> Maybe a
deleteIfNegative x = if x < 0 then Nothing else Just x
rejectWithNegatives :: (Num a, Ord a) => [a] -> Maybe [a]
• deleteIfNegative를 이용해서 rejectWithNegatives 를
구현하려면?
> let testList = [-5,3,2,-1,0]
> fmap deleteIfNegative testList
[Nothing,Just 3,Just 2,Nothing,Just 0]
No!!
29. Traversable 타입 클래
스
class (Functor t, Foldable t) => Traversable t where
traverse :: Applicative f => (a -> f b) -> t a -> f (t b)
sequenceA :: Applicative f => t (f a) -> f (t a)
-- These methods have default definitions.
-- They are merely specialised versions of the other two.
mapM :: Monad m => (a -> m b) -> t a -> m (t b)
sequence :: Monad m => t (m a) -> m (t a)
30. Traversable [] 정의
instance Traversable [] where
-- sequenceA :: Applicative f => [f a] -> f [a]
sequenceA [] = pure []
sequenceA (u:us) = (:) <$> u <*> sequenceA us
// or
instance Traversable [] where
sequenceA us =
foldr (u v -> (:) <$> u <*> v) (pure []) us
32. Traversable 예제
> let rejectWithNegatives = sequenceA . fmap deleteIfNegative
> :t rejectWithNegatives
rejectWithNegatives
:: (Num a, Ord a, Traversable t) => t a -> Maybe (t a)
> rejectWithNegatives testList
Nothing
> rejectWithNegatives [0..10]
Just [0,1,2,3,4,5,6,7,8,9,10]
33. traverse를 이용한
Traversable [] 정의
instance Traversable [] where
traverse _ [] = pure []
traverse f (x:xs) = (:) <$> f x <*> traverse f xs
-- Or, equivalently:
instance Traversable [] where
traverse f xs =
foldr (x v -> (:) <$> f x <*> v) (pure []) xs
34. traverse와 sequenceA
traverse :: (Traversable t, Applicative f) => (a -> f
b) -> t a -> f (t b)
traverse f xs = sequenceA $ fmap f xs
sequenceA :: (Traversable t, Applicative f) => t (f
a) -> f (t a)
sequenceA xs = traverse id xs