Skip to content

Instantly share code, notes, and snippets.

@rhz rhz/gist:945329
Created Apr 27, 2011

Embed
What would you like to do?
import qualified Data.Map as Map
type Mol = String
type Mixture = Map.Map Mol Integer
type Rxn = (Mixture, (Mixture -> Mixture), Double)
getActivities :: [Rxn] -> Mixture -> [Double]
getActivities rxns mixture =
let f acc mol sc = if sc == 1 -- sc is stoichiometric coefficient
then fromIntegral $ mixture Map.! mol
else let n = mixture Map.! mol
m = foldl' (*) 1 [n, n-1..n-sc+1] -- possible combinations of molecules mol
in acc * (fromIntegral m / fromIntegral sc)
activity (lhs, _, rate) = Map.foldlWithKey f rate lhs
in map activity rxns
{- Error:
test.hs:13:54:
No instance for (Fractional Integer)
arising from a use of `/'
Possible fix: add an instance declaration for (Fractional Integer)
In the second argument of `(*)', namely
`(fromIntegral m / fromIntegral sc)'
In the expression: acc * (fromIntegral m / fromIntegral sc)
In the expression:
let
n = fromIntegral $ mixture Map.! mol
m = foldl (*) 1 [n, n - 1 .. n - sc + 1]
in acc * (fromIntegral m / fromIntegral sc)
test.hs:15:10:
Couldn't match expected type `Double' with actual type `Integer'
Expected type: (Map.Map Mol a0, t0, Integer) -> Double
Actual type: (Map.Map Mol a0, t0, Integer) -> Integer
In the first argument of `map', namely `activity'
In the expression: map activity rxns
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.