SlideShare a Scribd company logo
1 of 16
Haskell
Number System



                Jaiyalas
Basic Number

Type      Precision    Instance            Data Structure

           Single-     Integral,
  Int                            minBound ... -1 | 0 | 1 ... maxBound
          Precision    Bounded
          Arbitrary-
Integer                Integral             ... -1 | 0 | 1 ...
          Precision
           Single-
 Float                 RealFloat                    -
          Precision
          Double-
Double                 RealFloat                    -
          Precision
More Number
  Type       Precision   Instance            Data Structure

  Ratio                              (Integral a) => Ratio a = !a :% !a
                 -       RealFrac
(Rational)                               Rational = Ratio Integer

Complex          -       Floating (RealFloat a) => Complex a = !a :+ !a
Type : Integer
Show
       Num   Fractional   Floating
 Eq                                  RealFloat
             Real         RealFrac
Ord
                    Integral
Enum
Type : Int
Show
       Num    Fractional   Floating
 Eq                                     RealFloat
              Real         RealFrac
Ord
                     Integral         Bounded
Enum
Type : Rational
Show
       Num   Fractional   Floating
 Eq                                  RealFloat
             Real         RealFrac
Ord
                    Integral
Enum
Type : Complex
Show
       Num   Fractional   Floating
 Eq                                  RealFloat
             Real         RealFrac
Ord
                    Integral
Enum
Type : Float & Double
Show
       Num   Fractional   Floating
 Eq                                  RealFloat
             Real         RealFrac
Ord
                    Integral
Enum
Casting Functions
fromInteger          (Num a) => Integer -> a

  toInteger         (Integral a) => a -> Integer

fromRational      (Fractional a) => Rational -> a

 toRational        (RealFrac a) => a -> Rational

                  (Integral a, Num b) => a -> b
fromIntegral
                     fromInteger . toInteger
fromRealFrac    (RealFrac a, Fractional b) => a -> b
 (realToFrac)       fromRational . toRational
Using Number
Focus on properties Class provided




Focus on a particular type
Using Number
Focus on properties Class provided
func :: (Fractional α) => α -> α




Focus on a particular type
func :: Double -> Double
Using Number
Focus on properties Class provided
func :: (Fractional α) => α -> α
     - α can be Float, Double,
          Rational or Complex

Focus on a particular type
func :: Double -> Double
     - Can be Double only
Using Number
Focus on what Fractional can do
func :: (Fractional α) => α -> α
     - α can be Float, Double,
          Rational or Complex

Focus on what Double can do
func :: Double -> Double
     - Can be Double only
Using Number
Focus on what Fractional can do
func :: (Fractional α) => α -> α
     - α can be Float, Double,
          Rational or Complex

Focus on what Double can do
func :: Double -> Double
     - Can be Double only
Using Number
Focus on what Fractional can do
func :: (Fractional α) => α -> α
     - α can be Float, Double,
          Rational or Complex

Focus on what Double can do
func :: Double -> Double
     - Can be Double only
THX.

More Related Content

What's hot

ES6 General Introduction
ES6 General IntroductionES6 General Introduction
ES6 General IntroductionThomas Johnston
 
Basic iOS Training with SWIFT - Part 2
Basic iOS Training with SWIFT - Part 2Basic iOS Training with SWIFT - Part 2
Basic iOS Training with SWIFT - Part 2Manoj Ellappan
 
Shapeless- Generic programming for Scala
Shapeless- Generic programming for ScalaShapeless- Generic programming for Scala
Shapeless- Generic programming for ScalaKnoldus Inc.
 
CallSharp: Automatic Input/Output Matching in .NET
CallSharp: Automatic Input/Output Matching in .NETCallSharp: Automatic Input/Output Matching in .NET
CallSharp: Automatic Input/Output Matching in .NETDmitri Nesteruk
 
Java: Introduction to Arrays
Java: Introduction to ArraysJava: Introduction to Arrays
Java: Introduction to ArraysTareq Hasan
 
Templates in C++
Templates in C++Templates in C++
Templates in C++Tech_MX
 
Introduction to ad-3.4, an automatic differentiation library in Haskell
Introduction to ad-3.4, an automatic differentiation library in HaskellIntroduction to ad-3.4, an automatic differentiation library in Haskell
Introduction to ad-3.4, an automatic differentiation library in Haskellnebuta
 
Blazing Fast, Pure Effects without Monads — LambdaConf 2018
Blazing Fast, Pure Effects without Monads — LambdaConf 2018Blazing Fast, Pure Effects without Monads — LambdaConf 2018
Blazing Fast, Pure Effects without Monads — LambdaConf 2018John De Goes
 
List-based Monadic Computations for Dynamically Typed Languages (Python version)
List-based Monadic Computations for Dynamically Typed Languages (Python version)List-based Monadic Computations for Dynamically Typed Languages (Python version)
List-based Monadic Computations for Dynamically Typed Languages (Python version)Wim Vanderbauwhede
 
O caml2014 leroy-slides
O caml2014 leroy-slidesO caml2014 leroy-slides
O caml2014 leroy-slidesOCaml
 
Operator overloading in C++
Operator overloading in C++Operator overloading in C++
Operator overloading in C++Ilio Catallo
 
Quark: A Purely-Functional Scala DSL for Data Processing & Analytics
Quark: A Purely-Functional Scala DSL for Data Processing & AnalyticsQuark: A Purely-Functional Scala DSL for Data Processing & Analytics
Quark: A Purely-Functional Scala DSL for Data Processing & AnalyticsJohn De Goes
 
Programming in scala - 1
Programming in scala - 1Programming in scala - 1
Programming in scala - 1Mukesh Kumar
 
TypeScript Presentation - Jason Haffey
TypeScript Presentation - Jason HaffeyTypeScript Presentation - Jason Haffey
TypeScript Presentation - Jason HaffeyRalph Johnson
 

What's hot (20)

ES6 General Introduction
ES6 General IntroductionES6 General Introduction
ES6 General Introduction
 
Basic iOS Training with SWIFT - Part 2
Basic iOS Training with SWIFT - Part 2Basic iOS Training with SWIFT - Part 2
Basic iOS Training with SWIFT - Part 2
 
Shapeless- Generic programming for Scala
Shapeless- Generic programming for ScalaShapeless- Generic programming for Scala
Shapeless- Generic programming for Scala
 
Lecture 3
Lecture 3Lecture 3
Lecture 3
 
CallSharp: Automatic Input/Output Matching in .NET
CallSharp: Automatic Input/Output Matching in .NETCallSharp: Automatic Input/Output Matching in .NET
CallSharp: Automatic Input/Output Matching in .NET
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
 
C++ string
C++ stringC++ string
C++ string
 
Java: Introduction to Arrays
Java: Introduction to ArraysJava: Introduction to Arrays
Java: Introduction to Arrays
 
Templates in C++
Templates in C++Templates in C++
Templates in C++
 
Introduction to ad-3.4, an automatic differentiation library in Haskell
Introduction to ad-3.4, an automatic differentiation library in HaskellIntroduction to ad-3.4, an automatic differentiation library in Haskell
Introduction to ad-3.4, an automatic differentiation library in Haskell
 
Blazing Fast, Pure Effects without Monads — LambdaConf 2018
Blazing Fast, Pure Effects without Monads — LambdaConf 2018Blazing Fast, Pure Effects without Monads — LambdaConf 2018
Blazing Fast, Pure Effects without Monads — LambdaConf 2018
 
List-based Monadic Computations for Dynamically Typed Languages (Python version)
List-based Monadic Computations for Dynamically Typed Languages (Python version)List-based Monadic Computations for Dynamically Typed Languages (Python version)
List-based Monadic Computations for Dynamically Typed Languages (Python version)
 
.NET F# Class constructor
.NET F# Class constructor.NET F# Class constructor
.NET F# Class constructor
 
O caml2014 leroy-slides
O caml2014 leroy-slidesO caml2014 leroy-slides
O caml2014 leroy-slides
 
Operator overloading in C++
Operator overloading in C++Operator overloading in C++
Operator overloading in C++
 
Quark: A Purely-Functional Scala DSL for Data Processing & Analytics
Quark: A Purely-Functional Scala DSL for Data Processing & AnalyticsQuark: A Purely-Functional Scala DSL for Data Processing & Analytics
Quark: A Purely-Functional Scala DSL for Data Processing & Analytics
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
Programming in scala - 1
Programming in scala - 1Programming in scala - 1
Programming in scala - 1
 
TypeScript Presentation - Jason Haffey
TypeScript Presentation - Jason HaffeyTypeScript Presentation - Jason Haffey
TypeScript Presentation - Jason Haffey
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 

Similar to Number System in Haskell

Python operators (1).pptx
Python operators (1).pptxPython operators (1).pptx
Python operators (1).pptxVaniHarave
 
Functional programming ii
Functional programming iiFunctional programming ii
Functional programming iiPrashant Kalkar
 
An introduction to functional programming with Swift
An introduction to functional programming with SwiftAn introduction to functional programming with Swift
An introduction to functional programming with SwiftFatih Nayebi, Ph.D.
 
Introduction to golang
Introduction to golangIntroduction to golang
Introduction to golangwww.ixxo.io
 
Scala - where objects and functions meet
Scala - where objects and functions meetScala - where objects and functions meet
Scala - where objects and functions meetMario Fusco
 
A Proposition for Business Process Modeling
A Proposition for Business Process ModelingA Proposition for Business Process Modeling
A Proposition for Business Process ModelingAng Chen
 
Introduction to Client-Side Javascript
Introduction to Client-Side JavascriptIntroduction to Client-Side Javascript
Introduction to Client-Side JavascriptJulie Iskander
 
Monoids - Part 1 - with examples using Scalaz and Cats
Monoids - Part 1 - with examples using Scalaz and CatsMonoids - Part 1 - with examples using Scalaz and Cats
Monoids - Part 1 - with examples using Scalaz and CatsPhilip Schwarz
 
Lecture20 vector
Lecture20 vectorLecture20 vector
Lecture20 vectornurkhaledah
 
Real World Haskell: Lecture 4
Real World Haskell: Lecture 4Real World Haskell: Lecture 4
Real World Haskell: Lecture 4Bryan O'Sullivan
 
Csharp4 operators and_casts
Csharp4 operators and_castsCsharp4 operators and_casts
Csharp4 operators and_castsAbed Bukhari
 
1.1 Real Numbers and Number Operations
1.1 Real Numbers and Number Operations1.1 Real Numbers and Number Operations
1.1 Real Numbers and Number OperationsSarah Stillwell
 

Similar to Number System in Haskell (20)

Operators & Casts
Operators & CastsOperators & Casts
Operators & Casts
 
Python operators (1).pptx
Python operators (1).pptxPython operators (1).pptx
Python operators (1).pptx
 
Functional programming ii
Functional programming iiFunctional programming ii
Functional programming ii
 
Python numbers
Python numbersPython numbers
Python numbers
 
An introduction to functional programming with Swift
An introduction to functional programming with SwiftAn introduction to functional programming with Swift
An introduction to functional programming with Swift
 
Cats in Scala
Cats in ScalaCats in Scala
Cats in Scala
 
Introduction to golang
Introduction to golangIntroduction to golang
Introduction to golang
 
Scala - where objects and functions meet
Scala - where objects and functions meetScala - where objects and functions meet
Scala - where objects and functions meet
 
A Proposition for Business Process Modeling
A Proposition for Business Process ModelingA Proposition for Business Process Modeling
A Proposition for Business Process Modeling
 
Introduction to Client-Side Javascript
Introduction to Client-Side JavascriptIntroduction to Client-Side Javascript
Introduction to Client-Side Javascript
 
Scala Bootcamp 1
Scala Bootcamp 1Scala Bootcamp 1
Scala Bootcamp 1
 
Meet scala
Meet scalaMeet scala
Meet scala
 
Introducing dimensional
Introducing dimensionalIntroducing dimensional
Introducing dimensional
 
Introducing scala
Introducing scalaIntroducing scala
Introducing scala
 
Monoids - Part 1 - with examples using Scalaz and Cats
Monoids - Part 1 - with examples using Scalaz and CatsMonoids - Part 1 - with examples using Scalaz and Cats
Monoids - Part 1 - with examples using Scalaz and Cats
 
10. funtions and closures IN SWIFT PROGRAMMING
10. funtions and closures IN SWIFT PROGRAMMING10. funtions and closures IN SWIFT PROGRAMMING
10. funtions and closures IN SWIFT PROGRAMMING
 
Lecture20 vector
Lecture20 vectorLecture20 vector
Lecture20 vector
 
Real World Haskell: Lecture 4
Real World Haskell: Lecture 4Real World Haskell: Lecture 4
Real World Haskell: Lecture 4
 
Csharp4 operators and_casts
Csharp4 operators and_castsCsharp4 operators and_casts
Csharp4 operators and_casts
 
1.1 Real Numbers and Number Operations
1.1 Real Numbers and Number Operations1.1 Real Numbers and Number Operations
1.1 Real Numbers and Number Operations
 

More from Yun-Yan Chi

Tezos Taipei Meetup #2 - 15/06/2019
Tezos Taipei Meetup #2 - 15/06/2019Tezos Taipei Meetup #2 - 15/06/2019
Tezos Taipei Meetup #2 - 15/06/2019Yun-Yan Chi
 
Traversing on Algebraic Datatype
Traversing on Algebraic DatatypeTraversing on Algebraic Datatype
Traversing on Algebraic DatatypeYun-Yan Chi
 
for "Parallelizing Multiple Group-by Queries using MapReduce"
for "Parallelizing Multiple Group-by Queries using MapReduce"for "Parallelizing Multiple Group-by Queries using MapReduce"
for "Parallelizing Multiple Group-by Queries using MapReduce"Yun-Yan Chi
 
Program Language - Fall 2013
Program Language - Fall 2013 Program Language - Fall 2013
Program Language - Fall 2013 Yun-Yan Chi
 
Machine X Language
Machine X LanguageMachine X Language
Machine X LanguageYun-Yan Chi
 
Examples for loopless
Examples for looplessExamples for loopless
Examples for looplessYun-Yan Chi
 
Data type a la carte
Data type a la carteData type a la carte
Data type a la carteYun-Yan Chi
 
Genetic programming
Genetic programmingGenetic programming
Genetic programmingYun-Yan Chi
 
Paper presentation: The relative distance of key point based iris recognition
Paper presentation: The relative distance of key point based iris recognitionPaper presentation: The relative distance of key point based iris recognition
Paper presentation: The relative distance of key point based iris recognitionYun-Yan Chi
 
Deriving a compiler and interpreter for a Multi-level
Deriving a compiler and interpreter for a Multi-level Deriving a compiler and interpreter for a Multi-level
Deriving a compiler and interpreter for a Multi-level Yun-Yan Chi
 
Constructing List Homomorphisms from Proofs
Constructing List Homomorphisms from ProofsConstructing List Homomorphisms from Proofs
Constructing List Homomorphisms from ProofsYun-Yan Chi
 

More from Yun-Yan Chi (13)

Tezos Taipei Meetup #2 - 15/06/2019
Tezos Taipei Meetup #2 - 15/06/2019Tezos Taipei Meetup #2 - 15/06/2019
Tezos Taipei Meetup #2 - 15/06/2019
 
Traversing on Algebraic Datatype
Traversing on Algebraic DatatypeTraversing on Algebraic Datatype
Traversing on Algebraic Datatype
 
for "Parallelizing Multiple Group-by Queries using MapReduce"
for "Parallelizing Multiple Group-by Queries using MapReduce"for "Parallelizing Multiple Group-by Queries using MapReduce"
for "Parallelizing Multiple Group-by Queries using MapReduce"
 
Program Language - Fall 2013
Program Language - Fall 2013 Program Language - Fall 2013
Program Language - Fall 2013
 
Machine X Language
Machine X LanguageMachine X Language
Machine X Language
 
Examples for loopless
Examples for looplessExamples for loopless
Examples for loopless
 
Insert 2 Merge
Insert 2 MergeInsert 2 Merge
Insert 2 Merge
 
Any tutor
Any tutorAny tutor
Any tutor
 
Data type a la carte
Data type a la carteData type a la carte
Data type a la carte
 
Genetic programming
Genetic programmingGenetic programming
Genetic programming
 
Paper presentation: The relative distance of key point based iris recognition
Paper presentation: The relative distance of key point based iris recognitionPaper presentation: The relative distance of key point based iris recognition
Paper presentation: The relative distance of key point based iris recognition
 
Deriving a compiler and interpreter for a Multi-level
Deriving a compiler and interpreter for a Multi-level Deriving a compiler and interpreter for a Multi-level
Deriving a compiler and interpreter for a Multi-level
 
Constructing List Homomorphisms from Proofs
Constructing List Homomorphisms from ProofsConstructing List Homomorphisms from Proofs
Constructing List Homomorphisms from Proofs
 

Number System in Haskell

  • 2. Basic Number Type Precision Instance Data Structure Single- Integral, Int minBound ... -1 | 0 | 1 ... maxBound Precision Bounded Arbitrary- Integer Integral ... -1 | 0 | 1 ... Precision Single- Float RealFloat - Precision Double- Double RealFloat - Precision
  • 3. More Number Type Precision Instance Data Structure Ratio (Integral a) => Ratio a = !a :% !a - RealFrac (Rational) Rational = Ratio Integer Complex - Floating (RealFloat a) => Complex a = !a :+ !a
  • 4. Type : Integer Show Num Fractional Floating Eq RealFloat Real RealFrac Ord Integral Enum
  • 5. Type : Int Show Num Fractional Floating Eq RealFloat Real RealFrac Ord Integral Bounded Enum
  • 6. Type : Rational Show Num Fractional Floating Eq RealFloat Real RealFrac Ord Integral Enum
  • 7. Type : Complex Show Num Fractional Floating Eq RealFloat Real RealFrac Ord Integral Enum
  • 8. Type : Float & Double Show Num Fractional Floating Eq RealFloat Real RealFrac Ord Integral Enum
  • 9. Casting Functions fromInteger (Num a) => Integer -> a toInteger (Integral a) => a -> Integer fromRational (Fractional a) => Rational -> a toRational (RealFrac a) => a -> Rational (Integral a, Num b) => a -> b fromIntegral fromInteger . toInteger fromRealFrac (RealFrac a, Fractional b) => a -> b (realToFrac) fromRational . toRational
  • 10. Using Number Focus on properties Class provided Focus on a particular type
  • 11. Using Number Focus on properties Class provided func :: (Fractional α) => α -> α Focus on a particular type func :: Double -> Double
  • 12. Using Number Focus on properties Class provided func :: (Fractional α) => α -> α - α can be Float, Double, Rational or Complex Focus on a particular type func :: Double -> Double - Can be Double only
  • 13. Using Number Focus on what Fractional can do func :: (Fractional α) => α -> α - α can be Float, Double, Rational or Complex Focus on what Double can do func :: Double -> Double - Can be Double only
  • 14. Using Number Focus on what Fractional can do func :: (Fractional α) => α -> α - α can be Float, Double, Rational or Complex Focus on what Double can do func :: Double -> Double - Can be Double only
  • 15. Using Number Focus on what Fractional can do func :: (Fractional α) => α -> α - α can be Float, Double, Rational or Complex Focus on what Double can do func :: Double -> Double - Can be Double only
  • 16. THX.