SlideShare a Scribd company logo
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

PDF
3 kotlin vs. java- what kotlin has that java does not
PDF
Perl and Haskell: Can the Twain Ever Meet? (tl;dr: yes)
PDF
Sigma type
PDF
Introduction to programming with dependent types in Scala
PPTX
Templates presentation
PDF
Lecture 5
PPT
C++: inheritance, composition, polymorphism
PDF
List-based Monadic Computations for Dynamic Languages
3 kotlin vs. java- what kotlin has that java does not
Perl and Haskell: Can the Twain Ever Meet? (tl;dr: yes)
Sigma type
Introduction to programming with dependent types in Scala
Templates presentation
Lecture 5
C++: inheritance, composition, polymorphism
List-based Monadic Computations for Dynamic Languages

What's hot (20)

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

Similar to Number System in Haskell (20)

PDF
High-Performance Haskell
PDF
Functional Programming in C++
PPT
lecture2.ppt FOR C PROGRAMMING AND DATA S TRUCT
PPT
lecture-ON-C.ppt BASIC WITH DEPTH CONTENT
PPT
lecture2.ppt...............................................
PPT
basic of C programming (token, keywords)lecture2.ppt
PDF
Reasoning about laziness
PPT
c token used in mathemetical programming
PDF
Chapter 9 : Polymorphism, Dynamic Typing, and Dynamic Binding
KEY
Programming haskell chapter10
PDF
Notes for GNU Octave - Numerical Programming - for Students 01 of 02 by Arun ...
PDF
Gnu octave help book 01 of 02
PDF
lec1).pdfbjkbvvttytxtyvkuvvtryccjbvuvibu
PDF
Abstract Interpretation for Dummies
PPT
Class03
PPT
Chapter-2 is for tokens in C programming
PPT
lecture2.ppt
PDF
Chpater 6
PDF
07. haskell Membership
PDF
Functional Programming In Mathematica
High-Performance Haskell
Functional Programming in C++
lecture2.ppt FOR C PROGRAMMING AND DATA S TRUCT
lecture-ON-C.ppt BASIC WITH DEPTH CONTENT
lecture2.ppt...............................................
basic of C programming (token, keywords)lecture2.ppt
Reasoning about laziness
c token used in mathemetical programming
Chapter 9 : Polymorphism, Dynamic Typing, and Dynamic Binding
Programming haskell chapter10
Notes for GNU Octave - Numerical Programming - for Students 01 of 02 by Arun ...
Gnu octave help book 01 of 02
lec1).pdfbjkbvvttytxtyvkuvvtryccjbvuvibu
Abstract Interpretation for Dummies
Class03
Chapter-2 is for tokens in C programming
lecture2.ppt
Chpater 6
07. haskell Membership
Functional Programming In Mathematica
Ad

More from Yun-Yan Chi (13)

PDF
Tezos Taipei Meetup #2 - 15/06/2019
PDF
Traversing on Algebraic Datatype
PDF
for "Parallelizing Multiple Group-by Queries using MapReduce"
PDF
Program Language - Fall 2013
PDF
Machine X Language
PDF
Examples for loopless
PDF
Insert 2 Merge
PDF
Any tutor
PDF
Data type a la carte
PDF
Genetic programming
PDF
Paper presentation: The relative distance of key point based iris recognition
PDF
Deriving a compiler and interpreter for a Multi-level
PDF
Constructing List Homomorphisms from Proofs
Tezos Taipei Meetup #2 - 15/06/2019
Traversing on Algebraic Datatype
for "Parallelizing Multiple Group-by Queries using MapReduce"
Program Language - Fall 2013
Machine X Language
Examples for loopless
Insert 2 Merge
Any tutor
Data type a la carte
Genetic programming
Paper presentation: The relative distance of key point based iris recognition
Deriving a compiler and interpreter for a Multi-level
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.