SlideShare a Scribd company logo
Introducing dimensional: Statically Checked
Physical Dimensions for Haskell
Björn Buckwalter & Doug McClean
January 2016
Why Check Dimensions?
Why Check Dimensions?
The usual reasons:
Mars Climate Orbiter
Gimli Glider (Air Canada Flight 143)
Why Check Dimensions?
The usual reasons:
Mars Climate Orbiter
Gimli Glider (Air Canada Flight 143)
Both incidents involved more than just software, but you get the
idea.
Why Check Dimensions?
Types as Documentation
Type system requires source code documentation of units
where raw numeric values enter/leave the program
Existing Solutions
units (Richard Eisenberg)
uom-plugin (Adam Gundry)
dimensional-tf (Björn Buckwalter)
Why dimensional?
What Goodies Do We Have?
Types Reflect Dimensions, Not Units
Type-Level and Term-Level Dimensions
Strongly Kinded
What Goodies Do We Have?
Dimensional Arithmetic
Convenient Quantity Synonyms
type DLength = 'Dim 1 0 0 0 0 0 0 (morally)
type Length a = Quantity DLength a
type Capacitance a = ...
Pretty Printing
Choose display units with showIn
Show instance defaults to SI base units
Exact Conversion Factors Using exact-pi
What Goodies Do We Have?
Ultra-Minimal Dependencies
No Need for TH or Solver Plugins
Even to define new units
What Don’t We Have?
Custom dimensions or polymorphism over basis
What Don’t We Have?
Custom dimensions or polymorphism over basis
No frogs / square mile
What Don’t We Have?
Custom dimensions or polymorphism over basis
No frogs / square mile
You have to live with our decision not to encode angle as a
dimension, although doing so is potentially useful from an
engineering perspective
What Don’t We Have?
Custom dimensions or polymorphism over basis
No frogs / square mile
You have to live with our decision not to encode angle as a
dimension, although doing so is potentially useful from an
engineering perspective
CGS ESU units are treated as equivalents in SI basis
What Don’t We Have?
Torsors
No absolute temperatures, absolute times, etc.
See dimensional-dk-experimental
What Don’t We Have?
A Functor instance
Intentionally omitted, since it can be used to break
scale-invariance
What Don’t We Have?
A solid benchmark suite
Appropriate INLINE, SPECIALIZE, and RULES pragmas arising
from same
What Don’t We Have?
A type solver plugin, like Adam Gundry’s
It’s very useful for code that is heavily polymorphic in dimension.
For example, our attempts to build a usable dimensionally-typed
linear algebra library have been hampered by error messages of the
form:
Couldn't match type `((x / iv) / u) * u'
with `((x / iv) / x) * x'
I’m working on developing this, but could use some help.
Examples
Getting Started
cabal update
cabal install dimensional
Getting Started
Here’s an example word problem from the readme file:
A car travels at 60 kilometers per hour for one mile, at 50 kph for
one mile, at 40 kph for one mile, and at 30 kph for one mile.
How many minutes does the journey take?
What is the average speed of the car?
How many seconds does the journey take, rounded up to the
next whole second?
Readme Example Continued
{-# LANGUAGE NoImplicitPrelude #-}
module ReadmeExample where
import Numeric.Units.Dimensional.Prelude
import Numeric.Units.Dimensional.NonSI (mile)
Readme Example Continued
{-# LANGUAGE NoImplicitPrelude #-}
module ReadmeExample where
import Numeric.Units.Dimensional.Prelude
import Numeric.Units.Dimensional.NonSI (mile)
leg :: Length Double
leg = 1 *~ mile
Readme Example Continued
{-# LANGUAGE NoImplicitPrelude #-}
module ReadmeExample where
import Numeric.Units.Dimensional.Prelude
import Numeric.Units.Dimensional.NonSI (mile)
leg :: Length Double
leg = 1 *~ mile
speeds :: [Velocity Double]
speeds = [60, 50, 40, 30] *~~ (kilo meter / hour)
Readme Example Continued
timeOfJourney :: Time Double
timeOfJourney = sum $ fmap (leg /) speeds
Readme Example Continued
timeOfJourney :: Time Double
timeOfJourney = sum $ fmap (leg /) speeds
averageSpeed :: Velocity Double
averageSpeed = _4 * leg / timeOfJourney
-- = (4 *~ one) * leg / timeOfJourney
Readme Example Continued
timeOfJourney :: Time Double
timeOfJourney = sum $ fmap (leg /) speeds
averageSpeed :: Velocity Double
averageSpeed = _4 * leg / timeOfJourney
-- = (4 *~ one) * leg / timeOfJourney
wholeSeconds :: Integer
wholeSeconds = ceiling $ timeOfJourney /~ second
Reading Aircraft State from FlightGear
readState :: [Double] -> VehicleState'
readState [r, p, y, rDot, pDot, yDot, ax, ay, az, slip, as,
= VehicleState' { ... }
where
_orientation = quaternionFromTaitBryan (y *~ degree)
_orientationRate = quaternionFromTaitBryan (yDot *~ d
_velocity = (V3 vx vy vz) *~~ (foot / second)
_acceleration = (V3 ax ay az) *~~ (foot / second / se
_sideSlip = slip *~ degree
_airspeed = as *~ (nauticalMile / hour)
_altitudeMSL = msl *~ foot
_altitudeAGL = agl *~ foot
_location = GeodeticPlace . fromJust $ lat <°> lon
_elapsedTime = et *~ second
_propellerSpeed = rpm *~ (revolution / minute)
_staticPressure = statpres *~ inHg
_dynamicPressure = dynpres *~ (poundForce / square fo
Defining Custom Units
Internals
Ecosystem
dimensional-codata
CODATA Values (not to be confused with codata. . . )
Speed of light
Planck constant
etc.
exact-pi
data ExactPi = Exact Integer Rational
| Approximate (forall a.Floating a => a)
approximateValue :: Floating a => ExactPi -> a
Provides an exact representation of rational multiples of integer
powers of pi
exact-pi
data ExactPi = Exact Integer Rational
| Approximate (forall a.Floating a => a)
approximateValue :: Floating a => ExactPi -> a
Provides an exact representation of rational multiples of integer
powers of pi
Provides Num, Fractional, Floating instances which fall
back to Approximate where necessary
exact-pi
data ExactPi = Exact Integer Rational
| Approximate (forall a.Floating a => a)
approximateValue :: Floating a => ExactPi -> a
Provides an exact representation of rational multiples of integer
powers of pi
Provides Num, Fractional, Floating instances which fall
back to Approximate where necessary
Non-zero such numbers form a group under multiplication
exact-pi
data ExactPi = Exact Integer Rational
| Approximate (forall a.Floating a => a)
approximateValue :: Floating a => ExactPi -> a
Provides an exact representation of rational multiples of integer
powers of pi
Provides Num, Fractional, Floating instances which fall
back to Approximate where necessary
Non-zero such numbers form a group under multiplication
All exactly defined units we have encountered in practice have
an exact representation
exact-pi
data ExactPi = Exact Integer Rational
| Approximate (forall a.Floating a => a)
approximateValue :: Floating a => ExactPi -> a
Provides an exact representation of rational multiples of integer
powers of pi
Provides Num, Fractional, Floating instances which fall
back to Approximate where necessary
Non-zero such numbers form a group under multiplication
All exactly defined units we have encountered in practice have
an exact representation
Universal type of Approximate defers computations with pi,
+, etc. until after the desired result type has been selected.
igrf and atmos
We have dimensionally typed wrappers around some libraries that
provide physical information, for example
igrf, which implements the International Geomagnetic
Reference Field
atmos, which implements the 1976 International Standard
Atmosphere
Future Work
Forthcoming Version 1.1
Improved support for dynamic quantities
Forthcoming Version 1.1
Improved support for dynamic quantities
Improvements to unit names that are necessary for proper
parsing
Forthcoming Version 1.1
Improved support for dynamic quantities
Improvements to unit names that are necessary for proper
parsing
Fixed-point quantities (details on next slide)
Forthcoming Version 1.1
Improved support for dynamic quantities
Improvements to unit names that are necessary for proper
parsing
Fixed-point quantities (details on next slide)
User manual
Forthcoming Fixed-Point Support
data Variant = DQuantity
| DUnit Metricality
type Quantity = Dimensional DQuantity
Forthcoming Fixed-Point Support
data Variant = DQuantity
| DUnit Metricality
type Quantity = Dimensional DQuantity
becomes
data Variant = DQuantity ExactPi -- scale factor
| DUnit Metricality
type SQuantity s = Dimensional (DQuantity s)
type Quantity = SQuantity One
Forthcoming Fixed-Point Support
import qualified GHC.TypeLits as N
import qualified Data.ExactPi.TypeLevel as E
-- A dimensionless number with n fractional bits,
-- using a representation of type a.
type Q n a = SQuantity (E.One E./
(E.ExactNatural (2 N.^ n))) DOne a
Forthcoming Fixed-Point Support
import qualified GHC.TypeLits as N
import qualified Data.ExactPi.TypeLevel as E
-- A dimensionless number with n fractional bits,
-- using a representation of type a.
type Q n a = SQuantity (E.One E./
(E.ExactNatural (2 N.^ n))) DOne a
-- A single-turn angle represented as
-- a signed 16-bit integer.
type Angle16 = SQuantity (E.Pi E./
(E.ExactNatural (2 N.^ 15)))
DPlaneAngle Int16
Forthcoming Fixed-Point Support
import qualified GHC.TypeLits as N
import qualified Data.ExactPi.TypeLevel as E
-- A dimensionless number with n fractional bits,
-- using a representation of type a.
type Q n a = SQuantity (E.One E./
(E.ExactNatural (2 N.^ n))) DOne a
-- A single-turn angle represented as
-- a signed 16-bit integer.
type Angle16 = SQuantity (E.Pi E./
(E.ExactNatural (2 N.^ 15)))
DPlaneAngle Int16
fast_sin :: Angle16 -> Q 15 Int16
Forthcoming Fixed-Point Support
import qualified GHC.TypeLits as N
import qualified Data.ExactPi.TypeLevel as E
-- A dimensionless number with n fractional bits,
-- using a representation of type a.
type Q n a = SQuantity (E.One E./
(E.ExactNatural (2 N.^ n))) DOne a
-- A single-turn angle represented as
-- a signed 16-bit integer.
type Angle16 = SQuantity (E.Pi E./
(E.ExactNatural (2 N.^ 15)))
DPlaneAngle Int16
fast_sin :: Angle16 -> Q 15 Int16
With Template Haskell we can do even better tricks.
Forthcoming Fixed-Point Support
data VehicleState = VehicleState {
lat :: Angle32,
lon :: Angle32,
altitutde :: [exact| mm ] Int32,
vnorth :: [exact| cm / s ] Int16,
veast :: [exact| cm / s ] Int16,
vdown :: [exact| cm / s ] Int16,
elapsedTime :: [exact| ms ] Word32,
pressure :: [exact| 0.1 Pa ] Word32
}
The only holdup here is some remaining work on the parser.
Fixed-Point Arithmetic
(+), (-) :: (Num a) => SQuantity s d a
-> SQuantity s d a
-> SQuantity s d a
abs, negate :: (Num a) => SQuantity s d a
-> SQuantity s d a
epsilon :: (Integral a) => SQuantity s d a
_0 :: Num a => SQuantity s d a
pi :: (Integral a, E.KnownExactPi s) => SQuantity s DOne a
Fixed-Point Arithmetic
(*~) :: (RealFrac a, Integral b, E.MinCtxt s a)
=> a -> Unit m d a -> SQuantity s d b
Fixed-Point Arithmetic
(*~) :: (RealFrac a, Integral b, E.MinCtxt s a)
=> a -> Unit m d a -> SQuantity s d b
rescale :: (Integral a, Integral b,
E.KnownExactPi s1, E.KnownExactPi s2)
=> SQuantity s1 d a -> SQuantity s2 d b
Fixed-Point Arithmetic
(*~) :: (RealFrac a, Integral b, E.MinCtxt s a)
=> a -> Unit m d a -> SQuantity s d b
rescale :: (Integral a, Integral b,
E.KnownExactPi s1, E.KnownExactPi s2)
=> SQuantity s1 d a -> SQuantity s2 d b
rescaleVia :: (Integral a, Integral c,
RealFrac b, Floating b,
E.KnownExactPi s1, E.KnownExactPi s2)
=> Proxy b
-> SQuantity s1 d a -> SQuantity s2 d c
Linear Algebra
An n * m matrix doesn’t have n * m independent choices of
dimension, it only has n + m - 1. You can multiply A and B only
when the relationship between the dimensions of the columns of A is
the inverse of the relationship between the dimensions of the rows
of B.
We have a library that models this, but it isn’t particularly useful
without the typechecker plugin because only monomorphic uses of it
are checked.
If we can fix it up it will be very useful for control engineering
problems.
Contributing
Suggestions and pull requests are welcome.
Issue tracker and source repository are at:
https://github.com/bjornbm/dimensional
Questions

More Related Content

What's hot

Acm aleppo cpc training ninth session
Acm aleppo cpc training ninth sessionAcm aleppo cpc training ninth session
Acm aleppo cpc training ninth session
Ahmad Bashar Eter
 
Unit 4 functions and pointers
Unit 4 functions and pointersUnit 4 functions and pointers
Unit 4 functions and pointers
kirthika jeyenth
 
Handling of character strings C programming
Handling of character strings C programmingHandling of character strings C programming
Handling of character strings C programming
Appili Vamsi Krishna
 
Strings in c
Strings in cStrings in c
Strings in c
vampugani
 
Acm aleppo cpc training second session
Acm aleppo cpc training second sessionAcm aleppo cpc training second session
Acm aleppo cpc training second session
Ahmad Bashar Eter
 
String C Programming
String C ProgrammingString C Programming
String C Programming
Prionto Abdullah
 
Strings in c++
Strings in c++Strings in c++
String in c
String in cString in c
String in c
Suneel Dogra
 
Unit 5 structure and unions
Unit 5 structure and unionsUnit 5 structure and unions
Unit 5 structure and unions
kirthika jeyenth
 
C programming - String
C programming - StringC programming - String
C programming - String
Achyut Devkota
 
Analisa Expression pada after effect menggungakan bahasa script
Analisa  Expression pada after effect menggungakan bahasa scriptAnalisa  Expression pada after effect menggungakan bahasa script
Analisa Expression pada after effect menggungakan bahasa script
VamelAfganisme Quartz
 
Strings
StringsStrings
Strings
Nilesh Dalvi
 
String c
String cString c
String in c programming
String in c programmingString in c programming
String in c programming
Devan Thakur
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
Tasnima Hamid
 
Strings in C
Strings in CStrings in C
Strings in C
Kamal Acharya
 
Strinng Classes in c++
Strinng Classes in c++Strinng Classes in c++
Strinng Classes in c++
Vikash Dhal
 
C string
C stringC string
Strings
StringsStrings
Strings
Imad Ali
 
The string class
The string classThe string class
The string class
Syed Zaid Irshad
 

What's hot (20)

Acm aleppo cpc training ninth session
Acm aleppo cpc training ninth sessionAcm aleppo cpc training ninth session
Acm aleppo cpc training ninth session
 
Unit 4 functions and pointers
Unit 4 functions and pointersUnit 4 functions and pointers
Unit 4 functions and pointers
 
Handling of character strings C programming
Handling of character strings C programmingHandling of character strings C programming
Handling of character strings C programming
 
Strings in c
Strings in cStrings in c
Strings in c
 
Acm aleppo cpc training second session
Acm aleppo cpc training second sessionAcm aleppo cpc training second session
Acm aleppo cpc training second session
 
String C Programming
String C ProgrammingString C Programming
String C Programming
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
 
String in c
String in cString in c
String in c
 
Unit 5 structure and unions
Unit 5 structure and unionsUnit 5 structure and unions
Unit 5 structure and unions
 
C programming - String
C programming - StringC programming - String
C programming - String
 
Analisa Expression pada after effect menggungakan bahasa script
Analisa  Expression pada after effect menggungakan bahasa scriptAnalisa  Expression pada after effect menggungakan bahasa script
Analisa Expression pada after effect menggungakan bahasa script
 
Strings
StringsStrings
Strings
 
String c
String cString c
String c
 
String in c programming
String in c programmingString in c programming
String in c programming
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
 
Strings in C
Strings in CStrings in C
Strings in C
 
Strinng Classes in c++
Strinng Classes in c++Strinng Classes in c++
Strinng Classes in c++
 
C string
C stringC string
C string
 
Strings
StringsStrings
Strings
 
The string class
The string classThe string class
The string class
 

Viewers also liked

Business
BusinessBusiness
Business
Li Jing
 
Temas 3,4, 5 y 7
Temas 3,4, 5 y 7Temas 3,4, 5 y 7
Temas 3,4, 5 y 7
YenderRomero
 
Customer Service Certificate
Customer Service CertificateCustomer Service Certificate
Customer Service CertificateMahmoud Zaki
 
BSMP - Letter of Support
BSMP - Letter of SupportBSMP - Letter of Support
BSMP - Letter of Support
Mateus Lins Claudino
 
WHAT IS STEM? The Future is Here - San Antonio, Texas.
WHAT IS STEM? The Future is Here - San Antonio, Texas. WHAT IS STEM? The Future is Here - San Antonio, Texas.
WHAT IS STEM? The Future is Here - San Antonio, Texas.
Jim "Brodie" Brazell
 
20141216_inrichtingsplan_sportpark_ijburg_webversie
20141216_inrichtingsplan_sportpark_ijburg_webversie20141216_inrichtingsplan_sportpark_ijburg_webversie
20141216_inrichtingsplan_sportpark_ijburg_webversieMartijn ter Hoeve
 
Quarter 1 lesson 4
Quarter 1 lesson 4Quarter 1 lesson 4
Quarter 1 lesson 4
EDLYN JOVEN
 
Social Media For Small Business
Social Media For Small BusinessSocial Media For Small Business
Social Media For Small Business
Nautic Studios
 
Multisource feedback & its utility
Multisource feedback & its utilityMultisource feedback & its utility
Multisource feedback & its utility
IAMRAreval2015
 
FNC - AFRICAN CHORAL FESTIVAL FOR PEACE
FNC - AFRICAN CHORAL FESTIVAL FOR PEACEFNC - AFRICAN CHORAL FESTIVAL FOR PEACE
FNC - AFRICAN CHORAL FESTIVAL FOR PEACE
josdiv
 
Вплив забруднення навколишнього середовища на статевий склад новонароджених
Вплив забруднення навколишнього середовища на статевий склад новонародженихВплив забруднення навколишнього середовища на статевий склад новонароджених
Вплив забруднення навколишнього середовища на статевий склад новонароджених
Taranoksana
 
Spotting an responding to institutional voids presentation
Spotting an responding to institutional voids presentationSpotting an responding to institutional voids presentation
Spotting an responding to institutional voids presentation
Ami Thomas
 
Enhancing Twitter Data Analysis with Simple Semantic Filtering: Example in Tr...
Enhancing Twitter Data Analysis with Simple Semantic Filtering: Example in Tr...Enhancing Twitter Data Analysis with Simple Semantic Filtering: Example in Tr...
Enhancing Twitter Data Analysis with Simple Semantic Filtering: Example in Tr...
Division of Biomedical Informatics, UC San Diego
 
Unit 302 Powerpoint
Unit 302 PowerpointUnit 302 Powerpoint
Unit 302 Powerpoint
Abigail_Dunne
 
Kentro water purifier
Kentro water purifierKentro water purifier
Kentro water purifier
Mohit Tripathi
 
Romeo & juliet's plot
Romeo & juliet's plotRomeo & juliet's plot
Romeo & juliet's plot
Rosa
 
Electric potential numericals
Electric potential numericalsElectric potential numericals
Electric potential numericals
manu jamwal
 
Key English Test- Cup 2 (book)
Key English Test- Cup 2 (book)Key English Test- Cup 2 (book)
Key English Test- Cup 2 (book)
Anh Nguyen
 
Preposition Usage
Preposition UsagePreposition Usage
Preposition Usage
Preposition Checker
 

Viewers also liked (19)

Business
BusinessBusiness
Business
 
Temas 3,4, 5 y 7
Temas 3,4, 5 y 7Temas 3,4, 5 y 7
Temas 3,4, 5 y 7
 
Customer Service Certificate
Customer Service CertificateCustomer Service Certificate
Customer Service Certificate
 
BSMP - Letter of Support
BSMP - Letter of SupportBSMP - Letter of Support
BSMP - Letter of Support
 
WHAT IS STEM? The Future is Here - San Antonio, Texas.
WHAT IS STEM? The Future is Here - San Antonio, Texas. WHAT IS STEM? The Future is Here - San Antonio, Texas.
WHAT IS STEM? The Future is Here - San Antonio, Texas.
 
20141216_inrichtingsplan_sportpark_ijburg_webversie
20141216_inrichtingsplan_sportpark_ijburg_webversie20141216_inrichtingsplan_sportpark_ijburg_webversie
20141216_inrichtingsplan_sportpark_ijburg_webversie
 
Quarter 1 lesson 4
Quarter 1 lesson 4Quarter 1 lesson 4
Quarter 1 lesson 4
 
Social Media For Small Business
Social Media For Small BusinessSocial Media For Small Business
Social Media For Small Business
 
Multisource feedback & its utility
Multisource feedback & its utilityMultisource feedback & its utility
Multisource feedback & its utility
 
FNC - AFRICAN CHORAL FESTIVAL FOR PEACE
FNC - AFRICAN CHORAL FESTIVAL FOR PEACEFNC - AFRICAN CHORAL FESTIVAL FOR PEACE
FNC - AFRICAN CHORAL FESTIVAL FOR PEACE
 
Вплив забруднення навколишнього середовища на статевий склад новонароджених
Вплив забруднення навколишнього середовища на статевий склад новонародженихВплив забруднення навколишнього середовища на статевий склад новонароджених
Вплив забруднення навколишнього середовища на статевий склад новонароджених
 
Spotting an responding to institutional voids presentation
Spotting an responding to institutional voids presentationSpotting an responding to institutional voids presentation
Spotting an responding to institutional voids presentation
 
Enhancing Twitter Data Analysis with Simple Semantic Filtering: Example in Tr...
Enhancing Twitter Data Analysis with Simple Semantic Filtering: Example in Tr...Enhancing Twitter Data Analysis with Simple Semantic Filtering: Example in Tr...
Enhancing Twitter Data Analysis with Simple Semantic Filtering: Example in Tr...
 
Unit 302 Powerpoint
Unit 302 PowerpointUnit 302 Powerpoint
Unit 302 Powerpoint
 
Kentro water purifier
Kentro water purifierKentro water purifier
Kentro water purifier
 
Romeo & juliet's plot
Romeo & juliet's plotRomeo & juliet's plot
Romeo & juliet's plot
 
Electric potential numericals
Electric potential numericalsElectric potential numericals
Electric potential numericals
 
Key English Test- Cup 2 (book)
Key English Test- Cup 2 (book)Key English Test- Cup 2 (book)
Key English Test- Cup 2 (book)
 
Preposition Usage
Preposition UsagePreposition Usage
Preposition Usage
 

Similar to Introducing dimensional

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
Fatih Nayebi, Ph.D.
 
The Swift Compiler and Standard Library
The Swift Compiler and Standard LibraryThe Swift Compiler and Standard Library
The Swift Compiler and Standard Library
Santosh Rajan
 
Peyton jones-2009-fun with-type_functions-slide
Peyton jones-2009-fun with-type_functions-slidePeyton jones-2009-fun with-type_functions-slide
Peyton jones-2009-fun with-type_functions-slide
Takayuki Muranushi
 
Computer programming 2 Lesson 10
Computer programming 2  Lesson 10Computer programming 2  Lesson 10
Computer programming 2 Lesson 10
MLG College of Learning, Inc
 
Patterns and practices for real-world event-driven microservices by Rachel Re...
Patterns and practices for real-world event-driven microservices by Rachel Re...Patterns and practices for real-world event-driven microservices by Rachel Re...
Patterns and practices for real-world event-driven microservices by Rachel Re...
Codemotion Dubai
 
Patterns and practices for real-world event-driven microservices
Patterns and practices for real-world event-driven microservicesPatterns and practices for real-world event-driven microservices
Patterns and practices for real-world event-driven microservices
Rachel Reese
 
unit 1 (1).pptx
unit 1 (1).pptxunit 1 (1).pptx
unit 1 (1).pptx
PriyadarshiniS28
 
C programing Tutorial
C programing TutorialC programing Tutorial
C programing Tutorial
Mahira Banu
 
Computation Chapter 4
Computation Chapter 4Computation Chapter 4
Computation Chapter 4
Inocentshuja Ahmad
 
Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4
Saranya saran
 
PPt Revision of the basics of python1.pptx
PPt Revision of the basics of python1.pptxPPt Revision of the basics of python1.pptx
PPt Revision of the basics of python1.pptx
tcsonline1222
 
Functions struct&union
Functions struct&unionFunctions struct&union
Functions struct&union
UMA PARAMESWARI
 
Function
FunctionFunction
Function
jayesh30sikchi
 
46630497 fun-pointer-1
46630497 fun-pointer-146630497 fun-pointer-1
46630497 fun-pointer-1
AmIt Prasad
 
Deep Dive Into Swift
Deep Dive Into SwiftDeep Dive Into Swift
Deep Dive Into Swift
Sarath C
 
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Chris Adamson
 
Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4
MKalpanaDevi
 
Functional programming with FSharp
Functional programming with FSharpFunctional programming with FSharp
Functional programming with FSharp
Daniele Pozzobon
 
Exploring Koltin on Android
Exploring Koltin on AndroidExploring Koltin on Android
Exploring Koltin on Android
Deepanshu Madan
 
TypeScript Presentation - Jason Haffey
TypeScript Presentation - Jason HaffeyTypeScript Presentation - Jason Haffey
TypeScript Presentation - Jason Haffey
Ralph Johnson
 

Similar to Introducing dimensional (20)

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
 
The Swift Compiler and Standard Library
The Swift Compiler and Standard LibraryThe Swift Compiler and Standard Library
The Swift Compiler and Standard Library
 
Peyton jones-2009-fun with-type_functions-slide
Peyton jones-2009-fun with-type_functions-slidePeyton jones-2009-fun with-type_functions-slide
Peyton jones-2009-fun with-type_functions-slide
 
Computer programming 2 Lesson 10
Computer programming 2  Lesson 10Computer programming 2  Lesson 10
Computer programming 2 Lesson 10
 
Patterns and practices for real-world event-driven microservices by Rachel Re...
Patterns and practices for real-world event-driven microservices by Rachel Re...Patterns and practices for real-world event-driven microservices by Rachel Re...
Patterns and practices for real-world event-driven microservices by Rachel Re...
 
Patterns and practices for real-world event-driven microservices
Patterns and practices for real-world event-driven microservicesPatterns and practices for real-world event-driven microservices
Patterns and practices for real-world event-driven microservices
 
unit 1 (1).pptx
unit 1 (1).pptxunit 1 (1).pptx
unit 1 (1).pptx
 
C programing Tutorial
C programing TutorialC programing Tutorial
C programing Tutorial
 
Computation Chapter 4
Computation Chapter 4Computation Chapter 4
Computation Chapter 4
 
Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4
 
PPt Revision of the basics of python1.pptx
PPt Revision of the basics of python1.pptxPPt Revision of the basics of python1.pptx
PPt Revision of the basics of python1.pptx
 
Functions struct&union
Functions struct&unionFunctions struct&union
Functions struct&union
 
Function
FunctionFunction
Function
 
46630497 fun-pointer-1
46630497 fun-pointer-146630497 fun-pointer-1
46630497 fun-pointer-1
 
Deep Dive Into Swift
Deep Dive Into SwiftDeep Dive Into Swift
Deep Dive Into Swift
 
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
 
Functions and pointers_unit_4
Functions and pointers_unit_4Functions and pointers_unit_4
Functions and pointers_unit_4
 
Functional programming with FSharp
Functional programming with FSharpFunctional programming with FSharp
Functional programming with FSharp
 
Exploring Koltin on Android
Exploring Koltin on AndroidExploring Koltin on Android
Exploring Koltin on Android
 
TypeScript Presentation - Jason Haffey
TypeScript Presentation - Jason HaffeyTypeScript Presentation - Jason Haffey
TypeScript Presentation - Jason Haffey
 

Recently uploaded

Requirement Traceability in Xen Functional Safety
Requirement Traceability in Xen Functional SafetyRequirement Traceability in Xen Functional Safety
Requirement Traceability in Xen Functional Safety
Ayan Halder
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
Rakesh Kumar R
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
XfilesPro
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
Green Software Development
 
zOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL DifferenceszOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL Differences
YousufSait3
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
Alina Yurenko
 
Malibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed RoundMalibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed Round
sjcobrien
 
Top 9 Trends in Cybersecurity for 2024.pptx
Top 9 Trends in Cybersecurity for 2024.pptxTop 9 Trends in Cybersecurity for 2024.pptx
Top 9 Trends in Cybersecurity for 2024.pptx
devvsandy
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative AnalysisOdoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Envertis Software Solutions
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
Łukasz Chruściel
 
UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
Peter Muessig
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
rodomar2
 
Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !
Marcin Chrost
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
Lecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptxLecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptx
TaghreedAltamimi
 
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
dakas1
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
Peter Muessig
 

Recently uploaded (20)

Requirement Traceability in Xen Functional Safety
Requirement Traceability in Xen Functional SafetyRequirement Traceability in Xen Functional Safety
Requirement Traceability in Xen Functional Safety
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
 
zOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL DifferenceszOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL Differences
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
 
Malibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed RoundMalibou Pitch Deck For Its €3M Seed Round
Malibou Pitch Deck For Its €3M Seed Round
 
Top 9 Trends in Cybersecurity for 2024.pptx
Top 9 Trends in Cybersecurity for 2024.pptxTop 9 Trends in Cybersecurity for 2024.pptx
Top 9 Trends in Cybersecurity for 2024.pptx
 
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative AnalysisOdoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
 
UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
 
Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
Lecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptxLecture 2 - software testing SE 412.pptx
Lecture 2 - software testing SE 412.pptx
 
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
 

Introducing dimensional

  • 1. Introducing dimensional: Statically Checked Physical Dimensions for Haskell Björn Buckwalter & Doug McClean January 2016
  • 3. Why Check Dimensions? The usual reasons: Mars Climate Orbiter Gimli Glider (Air Canada Flight 143)
  • 4. Why Check Dimensions? The usual reasons: Mars Climate Orbiter Gimli Glider (Air Canada Flight 143) Both incidents involved more than just software, but you get the idea.
  • 5. Why Check Dimensions? Types as Documentation Type system requires source code documentation of units where raw numeric values enter/leave the program
  • 6. Existing Solutions units (Richard Eisenberg) uom-plugin (Adam Gundry) dimensional-tf (Björn Buckwalter)
  • 8. What Goodies Do We Have? Types Reflect Dimensions, Not Units Type-Level and Term-Level Dimensions Strongly Kinded
  • 9. What Goodies Do We Have? Dimensional Arithmetic Convenient Quantity Synonyms type DLength = 'Dim 1 0 0 0 0 0 0 (morally) type Length a = Quantity DLength a type Capacitance a = ... Pretty Printing Choose display units with showIn Show instance defaults to SI base units Exact Conversion Factors Using exact-pi
  • 10. What Goodies Do We Have? Ultra-Minimal Dependencies No Need for TH or Solver Plugins Even to define new units
  • 11. What Don’t We Have? Custom dimensions or polymorphism over basis
  • 12. What Don’t We Have? Custom dimensions or polymorphism over basis No frogs / square mile
  • 13. What Don’t We Have? Custom dimensions or polymorphism over basis No frogs / square mile You have to live with our decision not to encode angle as a dimension, although doing so is potentially useful from an engineering perspective
  • 14. What Don’t We Have? Custom dimensions or polymorphism over basis No frogs / square mile You have to live with our decision not to encode angle as a dimension, although doing so is potentially useful from an engineering perspective CGS ESU units are treated as equivalents in SI basis
  • 15. What Don’t We Have? Torsors No absolute temperatures, absolute times, etc. See dimensional-dk-experimental
  • 16. What Don’t We Have? A Functor instance Intentionally omitted, since it can be used to break scale-invariance
  • 17. What Don’t We Have? A solid benchmark suite Appropriate INLINE, SPECIALIZE, and RULES pragmas arising from same
  • 18. What Don’t We Have? A type solver plugin, like Adam Gundry’s It’s very useful for code that is heavily polymorphic in dimension. For example, our attempts to build a usable dimensionally-typed linear algebra library have been hampered by error messages of the form: Couldn't match type `((x / iv) / u) * u' with `((x / iv) / x) * x' I’m working on developing this, but could use some help.
  • 20. Getting Started cabal update cabal install dimensional
  • 21. Getting Started Here’s an example word problem from the readme file: A car travels at 60 kilometers per hour for one mile, at 50 kph for one mile, at 40 kph for one mile, and at 30 kph for one mile. How many minutes does the journey take? What is the average speed of the car? How many seconds does the journey take, rounded up to the next whole second?
  • 22. Readme Example Continued {-# LANGUAGE NoImplicitPrelude #-} module ReadmeExample where import Numeric.Units.Dimensional.Prelude import Numeric.Units.Dimensional.NonSI (mile)
  • 23. Readme Example Continued {-# LANGUAGE NoImplicitPrelude #-} module ReadmeExample where import Numeric.Units.Dimensional.Prelude import Numeric.Units.Dimensional.NonSI (mile) leg :: Length Double leg = 1 *~ mile
  • 24. Readme Example Continued {-# LANGUAGE NoImplicitPrelude #-} module ReadmeExample where import Numeric.Units.Dimensional.Prelude import Numeric.Units.Dimensional.NonSI (mile) leg :: Length Double leg = 1 *~ mile speeds :: [Velocity Double] speeds = [60, 50, 40, 30] *~~ (kilo meter / hour)
  • 25. Readme Example Continued timeOfJourney :: Time Double timeOfJourney = sum $ fmap (leg /) speeds
  • 26. Readme Example Continued timeOfJourney :: Time Double timeOfJourney = sum $ fmap (leg /) speeds averageSpeed :: Velocity Double averageSpeed = _4 * leg / timeOfJourney -- = (4 *~ one) * leg / timeOfJourney
  • 27. Readme Example Continued timeOfJourney :: Time Double timeOfJourney = sum $ fmap (leg /) speeds averageSpeed :: Velocity Double averageSpeed = _4 * leg / timeOfJourney -- = (4 *~ one) * leg / timeOfJourney wholeSeconds :: Integer wholeSeconds = ceiling $ timeOfJourney /~ second
  • 28. Reading Aircraft State from FlightGear readState :: [Double] -> VehicleState' readState [r, p, y, rDot, pDot, yDot, ax, ay, az, slip, as, = VehicleState' { ... } where _orientation = quaternionFromTaitBryan (y *~ degree) _orientationRate = quaternionFromTaitBryan (yDot *~ d _velocity = (V3 vx vy vz) *~~ (foot / second) _acceleration = (V3 ax ay az) *~~ (foot / second / se _sideSlip = slip *~ degree _airspeed = as *~ (nauticalMile / hour) _altitudeMSL = msl *~ foot _altitudeAGL = agl *~ foot _location = GeodeticPlace . fromJust $ lat <°> lon _elapsedTime = et *~ second _propellerSpeed = rpm *~ (revolution / minute) _staticPressure = statpres *~ inHg _dynamicPressure = dynpres *~ (poundForce / square fo
  • 32. dimensional-codata CODATA Values (not to be confused with codata. . . ) Speed of light Planck constant etc.
  • 33. exact-pi data ExactPi = Exact Integer Rational | Approximate (forall a.Floating a => a) approximateValue :: Floating a => ExactPi -> a Provides an exact representation of rational multiples of integer powers of pi
  • 34. exact-pi data ExactPi = Exact Integer Rational | Approximate (forall a.Floating a => a) approximateValue :: Floating a => ExactPi -> a Provides an exact representation of rational multiples of integer powers of pi Provides Num, Fractional, Floating instances which fall back to Approximate where necessary
  • 35. exact-pi data ExactPi = Exact Integer Rational | Approximate (forall a.Floating a => a) approximateValue :: Floating a => ExactPi -> a Provides an exact representation of rational multiples of integer powers of pi Provides Num, Fractional, Floating instances which fall back to Approximate where necessary Non-zero such numbers form a group under multiplication
  • 36. exact-pi data ExactPi = Exact Integer Rational | Approximate (forall a.Floating a => a) approximateValue :: Floating a => ExactPi -> a Provides an exact representation of rational multiples of integer powers of pi Provides Num, Fractional, Floating instances which fall back to Approximate where necessary Non-zero such numbers form a group under multiplication All exactly defined units we have encountered in practice have an exact representation
  • 37. exact-pi data ExactPi = Exact Integer Rational | Approximate (forall a.Floating a => a) approximateValue :: Floating a => ExactPi -> a Provides an exact representation of rational multiples of integer powers of pi Provides Num, Fractional, Floating instances which fall back to Approximate where necessary Non-zero such numbers form a group under multiplication All exactly defined units we have encountered in practice have an exact representation Universal type of Approximate defers computations with pi, +, etc. until after the desired result type has been selected.
  • 38. igrf and atmos We have dimensionally typed wrappers around some libraries that provide physical information, for example igrf, which implements the International Geomagnetic Reference Field atmos, which implements the 1976 International Standard Atmosphere
  • 40. Forthcoming Version 1.1 Improved support for dynamic quantities
  • 41. Forthcoming Version 1.1 Improved support for dynamic quantities Improvements to unit names that are necessary for proper parsing
  • 42. Forthcoming Version 1.1 Improved support for dynamic quantities Improvements to unit names that are necessary for proper parsing Fixed-point quantities (details on next slide)
  • 43. Forthcoming Version 1.1 Improved support for dynamic quantities Improvements to unit names that are necessary for proper parsing Fixed-point quantities (details on next slide) User manual
  • 44. Forthcoming Fixed-Point Support data Variant = DQuantity | DUnit Metricality type Quantity = Dimensional DQuantity
  • 45. Forthcoming Fixed-Point Support data Variant = DQuantity | DUnit Metricality type Quantity = Dimensional DQuantity becomes data Variant = DQuantity ExactPi -- scale factor | DUnit Metricality type SQuantity s = Dimensional (DQuantity s) type Quantity = SQuantity One
  • 46. Forthcoming Fixed-Point Support import qualified GHC.TypeLits as N import qualified Data.ExactPi.TypeLevel as E -- A dimensionless number with n fractional bits, -- using a representation of type a. type Q n a = SQuantity (E.One E./ (E.ExactNatural (2 N.^ n))) DOne a
  • 47. Forthcoming Fixed-Point Support import qualified GHC.TypeLits as N import qualified Data.ExactPi.TypeLevel as E -- A dimensionless number with n fractional bits, -- using a representation of type a. type Q n a = SQuantity (E.One E./ (E.ExactNatural (2 N.^ n))) DOne a -- A single-turn angle represented as -- a signed 16-bit integer. type Angle16 = SQuantity (E.Pi E./ (E.ExactNatural (2 N.^ 15))) DPlaneAngle Int16
  • 48. Forthcoming Fixed-Point Support import qualified GHC.TypeLits as N import qualified Data.ExactPi.TypeLevel as E -- A dimensionless number with n fractional bits, -- using a representation of type a. type Q n a = SQuantity (E.One E./ (E.ExactNatural (2 N.^ n))) DOne a -- A single-turn angle represented as -- a signed 16-bit integer. type Angle16 = SQuantity (E.Pi E./ (E.ExactNatural (2 N.^ 15))) DPlaneAngle Int16 fast_sin :: Angle16 -> Q 15 Int16
  • 49. Forthcoming Fixed-Point Support import qualified GHC.TypeLits as N import qualified Data.ExactPi.TypeLevel as E -- A dimensionless number with n fractional bits, -- using a representation of type a. type Q n a = SQuantity (E.One E./ (E.ExactNatural (2 N.^ n))) DOne a -- A single-turn angle represented as -- a signed 16-bit integer. type Angle16 = SQuantity (E.Pi E./ (E.ExactNatural (2 N.^ 15))) DPlaneAngle Int16 fast_sin :: Angle16 -> Q 15 Int16 With Template Haskell we can do even better tricks.
  • 50. Forthcoming Fixed-Point Support data VehicleState = VehicleState { lat :: Angle32, lon :: Angle32, altitutde :: [exact| mm ] Int32, vnorth :: [exact| cm / s ] Int16, veast :: [exact| cm / s ] Int16, vdown :: [exact| cm / s ] Int16, elapsedTime :: [exact| ms ] Word32, pressure :: [exact| 0.1 Pa ] Word32 } The only holdup here is some remaining work on the parser.
  • 51. Fixed-Point Arithmetic (+), (-) :: (Num a) => SQuantity s d a -> SQuantity s d a -> SQuantity s d a abs, negate :: (Num a) => SQuantity s d a -> SQuantity s d a epsilon :: (Integral a) => SQuantity s d a _0 :: Num a => SQuantity s d a pi :: (Integral a, E.KnownExactPi s) => SQuantity s DOne a
  • 52. Fixed-Point Arithmetic (*~) :: (RealFrac a, Integral b, E.MinCtxt s a) => a -> Unit m d a -> SQuantity s d b
  • 53. Fixed-Point Arithmetic (*~) :: (RealFrac a, Integral b, E.MinCtxt s a) => a -> Unit m d a -> SQuantity s d b rescale :: (Integral a, Integral b, E.KnownExactPi s1, E.KnownExactPi s2) => SQuantity s1 d a -> SQuantity s2 d b
  • 54. Fixed-Point Arithmetic (*~) :: (RealFrac a, Integral b, E.MinCtxt s a) => a -> Unit m d a -> SQuantity s d b rescale :: (Integral a, Integral b, E.KnownExactPi s1, E.KnownExactPi s2) => SQuantity s1 d a -> SQuantity s2 d b rescaleVia :: (Integral a, Integral c, RealFrac b, Floating b, E.KnownExactPi s1, E.KnownExactPi s2) => Proxy b -> SQuantity s1 d a -> SQuantity s2 d c
  • 55. Linear Algebra An n * m matrix doesn’t have n * m independent choices of dimension, it only has n + m - 1. You can multiply A and B only when the relationship between the dimensions of the columns of A is the inverse of the relationship between the dimensions of the rows of B. We have a library that models this, but it isn’t particularly useful without the typechecker plugin because only monomorphic uses of it are checked. If we can fix it up it will be very useful for control engineering problems.
  • 56. Contributing Suggestions and pull requests are welcome. Issue tracker and source repository are at: https://github.com/bjornbm/dimensional