Created
March 12, 2011 20:33
-
-
Save kisielk/867537 to your computer and use it in GitHub Desktop.
The beginnings...
This file contains hidden or 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
| type Charge = Double | |
| type Distance = Double | |
| type Force = Double | |
| type Coord = Double | |
| type Mass = Double | |
| data Element = H | O | C deriving (Eq, Show, Read) | |
| data Position = Position { xPos :: Coord | |
| , yPos :: Coord | |
| , zPos :: Coord | |
| } deriving (Eq, Show, Read) | |
| data Atom = Atom { element :: Element | |
| , mass :: Mass | |
| , charge :: Charge | |
| , position :: Position | |
| } deriving (Eq, Show, Read) | |
| k_e = 8.987551787368176e10 | |
| class Dist a where | |
| (<->) :: a -> a -> Distance | |
| instance Dist Position where | |
| (<->) x y = sqrt sumOfSquares | |
| where sumOfSquares = xs ** 2 + ys ** 2 + zs ** 2 | |
| xs = xPos x - xPos y | |
| ys = yPos x - yPos y | |
| zs = zPos x - zPos y | |
| instance Dist Atom where | |
| (<->) x y = position x <-> position y | |
| electrostatic :: Atom -> Atom -> Force | |
| electrostatic a1 a2 = coulomb c1 c2 d | |
| where c1 = charge a1 | |
| c2 = charge a2 | |
| d = a1 <-> a2 | |
| coulomb :: Charge -> Charge -> Distance -> Force | |
| coulomb q1 q2 r = k_e * q1 * q2 / (r ** 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment