kudzu-forest / elm-atoms / Atoms

This module provides a custom type representing chemical elements and a record type for store informations about them.

Types


type alias AtomInfo a =
{ hydrogen : a
, helium : a
, lithium : a
, beryllium : a
, boron : a
, carbon : a
, nitrogen : a
, oxygen : a
, fluorine : a
, neon : a
, sodium : a
, magnesium : a
, aluminum : a
, silicon : a
, phosphorus : a
, sulfur : a
, chlorine : a
, argon : a
, potassium : a
, calcium : a
, scandium : a
, titanium : a
, vanadium : a
, chromium : a
, manganese : a
, iron : a
, cobalt : a
, nickel : a
, copper : a
, zinc : a
, gallium : a
, germanium : a
, arsenic : a
, selenium : a
, bromine : a
, krypton : a
, rubidium : a
, strontium : a
, yttrium : a
, zirconium : a
, niobium : a
, molybdenum : a
, technetium : a
, ruthenium : a
, rhodium : a
, palladium : a
, silver : a
, cadmium : a
, indium : a
, tin : a
, antimony : a
, tellurium : a
, iodine : a
, xenon : a
, cesium : a
, barium : a
, lanthanum : a
, cerium : a
, praseodymium : a
, neodymium : a
, promethium : a
, samarium : a
, europium : a
, gadolinium : a
, terbium : a
, dysprosium : a
, holmium : a
, erbium : a
, thulium : a
, ytterbium : a
, lutetium : a
, hafnium : a
, tantalum : a
, tungsten : a
, rhenium : a
, osmium : a
, iridium : a
, platinum : a
, gold : a
, mercury : a
, thallium : a
, lead : a
, bismuth : a
, polonium : a
, astatine : a
, radon : a
, francium : a
, radium : a
, actinium : a
, thorium : a
, protactinium : a
, uranium : a
, neptunium : a
, plutonium : a
, americium : a
, curium : a
, berkelium : a
, californium : a
, einsteinium : a
, fermium : a
, mendelevium : a
, nobelium : a
, lawrencium : a
, rutherfordium : a
, dubnium : a
, seaborgium : a
, bohrium : a
, hassium : a
, meitnerium : a
, darmstadtium : a
, roentgenium : a
, copernicium : a
, nihonium : a
, flerovium : a
, moscovium : a
, livermorium : a
, tennessine : a
, oganesson : a 
}

A Record type alias containing some information about all 118 atoms (as of 2024) in the periodic table. The names of atom in US English are used as the record key.

periodicTable.hydrogen.atomicNumber --> 1

periodicTable.carbon.atomicNumber --> 6


type Atom
    = H
    | He
    | Li
    | Be
    | B
    | C
    | N
    | O
    | F
    | Ne
    | Na
    | Mg
    | Al
    | Si
    | P
    | S
    | Cl
    | Ar
    | K
    | Ca
    | Sc
    | Ti
    | V
    | Cr
    | Mn
    | Fe
    | Co
    | Ni
    | Cu
    | Zn
    | Ga
    | Ge
    | As
    | Se
    | Br
    | Kr
    | Rb
    | Sr
    | Y
    | Zr
    | Nb
    | Mo
    | Tc
    | Ru
    | Rh
    | Pd
    | Ag
    | Cd
    | In
    | Sn
    | Sb
    | Te
    | I
    | Xe
    | Cs
    | Ba
    | La
    | Ce
    | Pr
    | Nd
    | Pm
    | Sm
    | Eu
    | Gd
    | Tb
    | Dy
    | Ho
    | Er
    | Tm
    | Yb
    | Lu
    | Hf
    | Ta
    | W
    | Re
    | Os
    | Ir
    | Pt
    | Au
    | Hg
    | Tl
    | Pb
    | Bi
    | Po
    | At
    | Rn
    | Fr
    | Ra
    | Ac
    | Th
    | Pa
    | U
    | Np
    | Pu
    | Am
    | Cm
    | Bk
    | Cf
    | Es
    | Fm
    | Md
    | No
    | Lr
    | Rf
    | Db
    | Sg
    | Bh
    | Hs
    | Mt
    | Ds
    | Rg
    | Cn
    | Nh
    | Fl
    | Mc
    | Lv
    | Ts
    | Og

A Custom type representing all 118 atoms (as of 2024) in the periodic table.

Data


type alias PeriodicTableInfo =
{ atomicNumber : Basics.Int
, period : Basics.Int
, group : Basics.Int
, symbol : String
, name : String 
}

A record type containing minimal informations for each atoms in the periodic table.

periodicTable : AtomInfo PeriodicTableInfo

An Atomsrecord containing PeriodicTableInfo of the all 118 atoms.

periodicTable.sodium -->
    { atomicNumber = 11
    , period = 3
    , group = 1
    , symbol = "Na"
    , name = "sodium"
    }

Creation

create : (Atom -> a) -> AtomInfo a

Returns new AtomInfo having specified informations.

type Metality
    = Metal
    | NonMetal

metality : AtomInfo Metality
metality =
    create
        (\atom ->
            let
                { period, group } =
                    get atom periodicTable
            in
            if
                (period == 1)
                    || (period <= 6)
                            && (group >= 10 + period)
            then
                NonMetal
            else
                Metal
        )

get Xe metality --> NonMetal

get U metality --> Metal

Query

get : Atom -> AtomInfo a -> a

Returns value of an atom stored in the second argument. You also can directly access record like atoms.hydrogen, which has a better performance in return for a bit more keyboad typing.

calcium : PeriodicTableInfo
calcium = get Ca periodicTable

calcium.period --> 4

calcium.group --> 2

filter : (a -> Basics.Bool) -> AtomInfo a -> List Atom

Returns list of atoms that passed a test ordered with ascending atomic number.

first10Atoms : List Atom
first10Atoms =
    filter (\a -> a.atomicNumber <= 10) periodicTable -->
        [ H
        , He
        , Li
        , Be
        , B
        , C
        , N
        , O
        , F
        , Ne
        ]