patternMinor
Module for isotopic masses and abundances
Viewed 0 times
isotopicmassesabundancesmoduleforand
Problem
I have written a small module for accessing data on isotope masses and relative abundances. My long term aim is to build tools in Haskell for working with mass spectrometry data. Any comments on how to improve this module will be greatly appreciated. I am considering uploading this to Hackage, though I want to be sure it is of sufficient quality.
https://github.com/Michaelt293/Element-isotopes
The relevent code is provided below.
Data on isotope masses and abundances is provided in a map (only the first three elements are given as an example).
`elements = Map.fromLi
https://github.com/Michaelt293/Element-isotopes
The relevent code is provided below.
import qualified Data.Map as Map
import qualified Data.Maybe as Maybe
import qualified Data.List as List
type IsotopeMass = Double
type IsotopeAbundance = Double
type ElementName = String
type AtomicNumber = Integer
type NumberOfNeutrons = Integer
type IsotopeData = (AtomicNumber, NumberOfNeutrons)
type IntegerMass = Integer
data Isotope = Isotope { isotopeData :: IsotopeData
, isotopeMass :: IsotopeMass
, isotopeAbundance :: IsotopeAbundance
} deriving (Show, Eq, Ord)
data Element = Element { atomicNumber :: AtomicNumber
, elementName :: ElementName
, isotopes :: [Isotope]
} deriving (Show, Eq, Ord)
data ElementSymbol = 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 | Th |
Pa | U deriving (Show, Read, Eq, Ord, Enum, Bounded)
Data on isotope masses and abundances is provided in a map (only the first three elements are given as an example).
`elements = Map.fromLi
Solution
Just trivial changes but how about:
Rely more on point-free, for example
Use names such as
I personally really prefer
`
Rely more on point-free, for example
monoisotopicMass = isotopeMass . mostAbunantIsotope
isotopeIntegerMasses = map (sumPair . isotopeData) . getIsotopes
where sumPair (atomicNum, protons) = atomicNum + protons
Use names such as
isotopes instead of getIsotopes etc.getIsotopes feels imperative; consider map getIsotopes symbols vs map isotopes symbols or even isotopes symbolsI personally really prefer
fmap and ` over map. What's nice about is that it makes it appear as you're applying a function to a list:
sqrt [2.0,3.0,4.0,5.0]
which reads a little bit like
sqrt $ 2.0`
Context
StackExchange Code Review Q#108494, answer score: 4
Revisions (0)
No revisions yet.