has: Generic Haskell's Record Accessors

[ bsd3, data, library ] [ Propose Tags ]

Modules

[Index]

Flags

Automatic Flags
NameDescriptionDefault
test

Build test program.

Disabled

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

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1, 0.2, 0.2.1, 0.3, 0.4, 0.4.0.1, 0.5.0.0, 0.5.0.1, 0.6.0.1
Dependencies base (>=4 && <5), HUnit, test-framework, test-framework-hunit [details]
License BSD-3-Clause
Copyright (c) Yusaku Hashimoto 2010
Author Yusaku Hashimoto
Maintainer Yusaku Hashimoto <nonowarn@gmail.com>
Category Data
Home page http://github.com/nonowarn/has
Source repo head: git clone git://github.com/nonowarn/has.git
Uploaded by YusakuHashimoto at 2010-03-03T00:46:11Z
Distributions
Reverse Dependencies 2 direct, 0 indirect [details]
Executables test
Downloads 7068 total (22 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for has-0.2

[back to package description]

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)