From f52f1356b74adb4fa0b57f63d4944ebb442810f9 Mon Sep 17 00:00:00 2001 From: Mistivia Date: Thu, 22 May 2025 23:54:23 +0800 Subject: fix readme --- Readme.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Readme.md b/Readme.md index c3b408c..d26ada0 100644 --- a/Readme.md +++ b/Readme.md @@ -6,23 +6,23 @@ To get started: import Accessor -An accessors is a getter with a setter. +An accessor is a getter with a setter. -For record fields, the accessors are defined as follow: +For record fields, the accessors are defined as follows: data Point = Point {_x :: Int, _y :: Int} x = accessor _x (\elem record -> record {x = elem}) y = accessor _y (\elem record -> record {y = elem}) -With an accessor, you can view, set, and tranform data of the record: +With an accessor, you can view, set, and transform data of the record: point = Point 1 2 view x point -- 1 set x 3 point -- Point 3 2 over x (+1) point -- Point 2 2 -For a nested record, accessors can be composed usine `(#)`: +For a nested record, accessors can be composed using `(#)`: data Line = Line {_start :: Point, _end :: Point} start = accessor _start (\elem record -> record {_start = elem}) @@ -36,11 +36,11 @@ For a nested record, accessors can be composed usine `(#)`: line = Line (Point 1 2) (Point 3 4) start_x = view (start # x) line -- 1 - end_y = view (start # y) line -- 4 + end_y = view (end # y) line -- 4 -If the field is a functor, the accessor should be composed with the next accesor using `(#>)`. For exmaple: +If the field is a functor, the accessor should be composed with the next accessor using `(#>)`. For example: - data Person = Person {_name :: String, _addr = Maybe Address } + data Person = Person {_name :: String, _addr :: Maybe Address } name = accessor _name (\elem record -> record {_name = elem}) addr= accessor _addr (\elem record -> record {_addr = elem}) @@ -62,9 +62,9 @@ You can view/modify Alice's address detail: s = view (addr #> detail) alice -- Just "Shanghai" -`fmap` will make sure `Nothing` be handled properly. +The use of `fmap` inside of `(#>)` ensures that `Nothing` is handled properly. -Aceesor of the nth element of a list is `listAt n`, and for 0~9, there are shortcuts `_0`~`_9`. +Accessor of the nth element of a list is `listAt n`, and for 0 to 9, there are shortcuts: `_0` to `_9`. view _1 [1,2,3] -- 2 view (_1 # _1) [[1,2,3], [4,5,6]] -- 5 @@ -74,6 +74,6 @@ Aceesor of the nth element of a list is `listAt n`, and for 0~9, there are short Lists are also functors, so you can `fmap` over it using `(#>)`, which is the same as `map`: over (self #> self) (+1) [1,2,3] -- [2,3,4] - over (_1 #> self) (+1) [[1,2], [2,3]] -- [[1,2],[4,5]] + over (_1 #> self) (+1) [[1,2], [3,4]] -- [[1,2],[4,5]] -- cgit v1.0