[Haskell-beginners] Some guidance

David McBride toad3k at gmail.com
Tue Jul 2 03:17:52 CEST 2013

You can export specific pieces explicitely, ie:

module AutoTrader.MtGox.Types (MtGoxTicker(MtGoxTicker), tkLast,
tkLastAll, etc...) where

and it will not export the _ field accessors.  It is a hassle, but
that's the price you pay for all that code generation.

As for the two versions of MtGoxTicker, if they have a lot in common,
you might think about using type classes for that.

class BasicInfo a where
  tkHigh :: Lens a a MtGoxPrice MtGoxPrice
  tkLow :: Lens a a MtGoxPrice MtGoxPrice
--  ...

class ComplexInfo a where
  tkAvg :: Lens a a MtGoxPrice MtGoxPrice
--  ...

data MtGoxTickerBrief = MtGoxTickerBrief {
  _briefHigh :: MtGoxPrice,
  _briefLow :: MtGoxPrice
data MtGoxTickerFull = MtGoxTickerFull {
  _fullHigh :: MtGoxPrice,
  _fullLow :: MtGoxPrice,
  _fullAvg :: MtGoxPrice

makeLenses ''MtGoxTickerBrief
makeLenses ''MtGoxTickerFull

instance BasicInfo MtGoxTickerBrief where
  tkHigh = briefHigh
  tkLow = briefLow

instance BasicInfo MtGoxTickerFull where
  tkHigh = fullHigh
  tkLow = fullLow

instance ComplexInfo MtGoxTickerFull where
  tkAvg = fullAvg

I'm sure there are other ways of dealing with it, but this works.

More information about the Beginners mailing list