Created
April 27, 2011 22:01
-
-
Save rhz/945329 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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