Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix overloaded labels example #221

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 2 additions & 21 deletions tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -5898,27 +5898,8 @@ extract :: IsLabel "id" t => t
extract = #id
```

```haskell
{-# LANGUAGE OverloadedLabels #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE ExistentialQuantification #-}

import GHC.Records (HasField(..)) -- Since base 4.10.0.0
import GHC.OverloadedLabels (IsLabel(..))

data S = MkS { foo :: Int }
data T x y z = forall b . MkT { foo :: y, bar :: b }

instance HasField x r a => IsLabel x (r -> a) where
fromLabel = getField

main :: IO ()
main = do
print (#foo (MkS 42))
print (#foo (MkT True False))
```
~~~~ {.haskell include="src/03-monad-transformers/overloaded_labels.hs"}
~~~~

This is used in more advanced libraries like [Selda] which do object relational
mapping between Haskell datatype fields and database columns.
Expand Down