This is my first program using Haskell. I'm writing it to put into practice all that I've read about FP. The first thing I'm trying to figure out is how to model the data that I'll be pulling out of my DB (eventually I'll be writing to the DB as well). I started with my users
table and wrote something like this
module Model (User) where
class Audited a where
creationDate :: a -> Integer
lastUpdatedDate :: a -> Integer
creationUser :: a -> User
lastUpdatedUser :: a -> User
class Identified a where
id :: a -> Integer
data User = User {userId :: Integer}
instance Identified User where
id u = userId u
and
module Main (main) where
import Model (User)
data Point = Pt {pointx, pointy :: Float}
instance Show Point where
show (Pt x y) = "(" ++ show x ++ ", " ++ show y ++ ")"
main :: IO ()
main = do
print $ Pt 1 2
(The Point
stuff is just me testing... this is my very first Haskell code ever)
This code does not compile, but I'm not really concerned about that yet -- the big thing is getting my types set up in a good way.
Here is a list of questions that I have
- What is the best way to model record-based data in Haskell?
- Most of my tables have audit information and opaque IDs. How can I take advantage of this using the Haskell type system? You can see that I created Audited and Identified classes. Is this a good approach?
- Is this even a good application for Haskell? I was considering using Clojure as it could interoperate with Java (this application is currently written in Java).