sifflet-2.3.0: Simple, visual, functional language for learning about recursion.

Safe HaskellSafe
LanguageHaskell2010

Data.Number.Sifflet

Description

This module provides the Sifflet Number type and many operations upon it. Most of the operations are provided by making Number an instance of the classes Num, Real, Enum, Integral, Fractional, Floating, and RealFrac. These are, I think, all of the normal Haskell numeric type classes *except* RealFloat. There are also a few functions defined in addition to the class methods.

The *primary* purpose of this module is to be the library module used by Sifflet programs exported to Haskell. The *secondary* purpose (maybe no less important, but realized after the first) is to implement the Sifflet number Values (previously done with the VInt and VFloat constructors).

Synopsis

Documentation

data Number Source

A Number represents a real number, which can be exact (Integer) or inexact (Double).

Constructors

Exact Integer 
Inexact Double 

Instances

Enum Number Source

In Haskell both Intgeger and Double are instances of Enum, so Number should be an instance too. Also, this is a prerequisite of being an instance of Integral.

Eq Number Source 
Floating Number Source

Numbers are Floating, i.e., support exponential, log, and trig functions. This works directly for inexact Numbers, and otherwise by conversion from Exact to Inexact.

Fractional Number Source

Numbers are Fractional, i.e., support division and conversion from Rational. This works directly for inexact Numbers, and otherwise by conversion from Exact to Inexact.

Integral Number Source

Numbers are Integral, i.e., can do integer division and convert to Integer. However, there is a restriction: this only works for Exact numbers; for Inexact, there will be an error. Some may see this as regrettable, but how is it different in principle from division, which doesn't work for zero divisors, and square root, which doesn't work for negative numbers?

Num Number Source

Number as an instance of Num

Ord Number Source

Number as an ordered type

Read Number Source 
Real Number Source

Numbers are Real, i.e., can be converted to Rational

RealFrac Number Source 
Show Number Source

This Show instance will not be compatible with the derived Read instance above -- so fix it. (And yet, mysteriously, ghci accepts 1 and 1.0 as Number literals.)

Repr Number Source 

isExact :: Number -> Bool Source

Tell whether a Number is exact

toInexact :: Number -> Number Source

Take a number, which may be exact or inexact, and produce the inexact number which equals it. Note that there is no inverse function toExact, because some inexact numbers like 3.5 are not equal to any exact number. The class RealFrac provides methods round, ceiling, floor, truncate for converting to exact numbers.