The has package

[Tags: bsd3, library]

In other words, weak extensible records.

Usage: http://github.com/nonowarn/has/blob/master/README.md

And its test would be helpful: http://github.com/nonowarn/has/blob/master/test/Main.hs


[Skip to ReadMe]

Properties

Versions0.1, 0.2, 0.2.1, 0.3, 0.4, 0.4.0.1, 0.5.0.0, 0.5.0.1
Change logNone available
Dependenciesbase (==4.*), HUnit, QuickCheck (==2.*), test-framework, test-framework-hunit [details]
LicenseBSD3
Copyright(c) Yusaku Hashimoto 2010
AuthorYusaku Hashimoto
MaintainerYusaku Hashimoto <nonowarn@gmail.com>
StabilityExperimental
CategoryData
Home pagehttp://github.com/nonowarn/has
Source repositoryhead: git clone git://github.com/nonowarn/has.git
Executablestest
UploadedWed Mar 10 05:21:32 UTC 2010 by YusakuHashimoto
DistributionsNixOS:0.5.0.1
Downloads1165 total (44 in last 30 days)
Votes
0 []
StatusDocs uploaded by user
Build status unknown [no reports yet]

Modules

[Index]

Flags

NameDescriptionDefault
testBuild test program.Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainers' corner

For package maintainers and hackage trustees

Readme for has-0.2.1

has

This is a library which provides generic accessors for records.

-- This example is based on fclabel's one: http://hackage.haskell.org/package/fclabels

import Data.Has

import Control.Arrow

type Person = Name :*: Age :*: Sex :*: Place
type Place  = City :*: Country

newtype Name = Name { unName :: String }
newtype Age  = Age  { unAge  :: Int    }
data    Sex  = Male | Female
newtype City = City { unCity :: String }
newtype Country = Country { unCountry :: String }

nonowarn :: Person
nonowarn =   Name "nonowarn"
         :*: Age 17
         :*: Male
         :*: City "Yokohama"
         :*: Country "Japan"

getAge :: (Has Age a) => a -> Int
getAge = unAge . prj

moveToKyoto :: (Has City a) => a -> a
moveToKyoto = inj (City "Kyoto")

getCity :: (Has City a) => a -> String
getCity = unCity . prj

spendFourYears :: (Has Age a) => a -> a
spendFourYears = upd (Age . (+4) . unAge)

test = (21,"Kyoto") == ((getAge &&& getCity) . spendFourYears . moveToKyoto $ nonowarn)