Skip to content

Totally abstract numbers #20

@dmcclean

Description

@dmcclean

I have a EDSL with lots of terms that are polymorphic over any Floating type. I wish to perform some abstract interpretation over them looking at properties other than what they do to the numbers (things like signal names and other metadata). Right now I have to pick a Floating type essentially arbitrarily, even though I end up ignoring it.

Since there isn't a Num instance for (), I propose a type like:

data AbstractNumber = AbstractNumber deriving (Eq, Ord)

binop :: AbstractNumber -> AbstractNumber -> AbstractNumber
binop AbstractNumber AbstractNumber = AbstractNumber

instance Num AbstractNumber where
  (+) = binop
  (*) = binop
  negate = id
  abs = id
  signum = id
  fromInteger = const AbstractNumber

-- similarly for Fractional and Floating

Is this a good fit for this package? If so I can draft a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions