MyNixOS website logo
Description

Typeclasses for type conversion mappings.

This package provides the typeclasses From and TryFrom.

The From.From typeclass provides From.from :: a -> b. It is an interface a pair of types that can be converted from one to another.

The From.TryFrom typeclass provides From.tryFrom :: a -> Prelude.Maybe
b. It is an interface for a pair of types that can be converted from one to another, safely handling the possibility of a failure.

Default From.From instances are provided for some integral types in base, using Prelude.fromIntegral.

This is the core package. This package itself is not spectacularly useful. One example of immediate usefulness would be the from-string package.

If you are interested, you may want to check the project README.md (not the package README.md) as well.

from

Note that this package is a part of the "project" that includes from and from-string. For the general rationale behind this idea, see README.md under the project root.

This Haskell library package provides the From and TryFrom typeclasses.

The From typeclass provides from :: a -> b. It is an interface for types that can be converted from/to each other.

The TryFrom typeclass provides tryFrom :: a -> Maybe b. It is an interface for types that can be converted from/to each other, with the possibility of a failure.

This package has 1 dependency: base.

Instances

It is difficult and often impossible to "selectively" import/export typeclass instances. Therefore, we need to be careful about what instances to provide by default.

There are base functions, some of them even in Prelude, that basically serve as a less general version of from. Examples include fromIntegral and fromEnum. However, naively defining

  • instance (Integral a, Num b) => From a b and
  • instance (Enum a) => From a Int

will quickly lead us to trouble:

    • Overlapping instances for From Int16 Int
        arising from a use of ‘from’
      Matching instances:
        instance (Integral a, Num b) => From a b
        instance Enum a => From a Int
      ...

Therefore, this package does not provide such "contextual" instances.

Instead, concrete instances are provided. For example, all pairs (excluding self to self) of these integral types are instantiated using fromIntegral:

  • Int
  • Integer
  • Int8
  • Int16
  • Int32
  • Int64
  • Word8
  • Word16
  • Word32
  • Word64

Each type can be both source and destination of from. Additional types are instantiated as destination-only:

  • Float
  • Double.
Metadata

Version

1.0.0.1

License

Platforms (76)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-linux
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows