on dev help sign in
release notes and scrap stuff
commit05d3a493270398907e7c231186eabf959e7d3ba5 authorEitan Chatav <eitan.chatav@gmail.com> dateSat 7 Jul 2018, 11:37 (8 years ago) parent38e5f77
2 files changed+20−4
RELEASE NOTES.md+7 scrap-your-nils.md+13−4
RELEASE NOTES.md+7
@@ -1,5 +1,12 @@
11## RELEASE NOTES
22
3+### Version 0.3.1 - July 7, 2018
4+
5+Version 0.3.1 of Squeal enables the "Scrap your Nils" trick for
6+heterogeneous lists of `Alias`es, `Aliased` expressions, `PGlabel`s and `By`s
7+with the typeclasses `IsLabel`, `IsQualified`, `Aliasable`, and `IsPGlabel`,
8+to eliminate all need of using `Nil` in a list.
9+
310### Version 0.3 - June 26, 2018
411
512Version 0.3 of Squeal adds views as well as composite and enumerated types to Squeal.
scrap-your-nils.md+13−4
@@ -9,6 +9,7 @@ It's also the same as the [NP]
99datatype from the [generics-sop](http://hackage.haskell.org/package/generics-sop) library.
1010Squeal makes heavy use of this type.
1111
12+```Haskell
1213>>> import Generics.SOP (NP(..))
1314>>> :i NP
1415type role NP representational nominal
@@ -17,37 +18,45 @@ data NP (a :: k -> *) (b :: [k]) where
1718 (:*) :: forall k (a :: k -> *) (x :: k) (xs :: [k]).
1819 (a x) -> (NP a xs) -> NP a (x : xs)
1920 -- Defined in ‘Generics.SOP.NP’
21+```
2022
2123This type allows us to construct "product" types, where the types of the individual
2224"terms" are hosted at the type level.
2325
26+```Haskell
2427>>> :set -XDataKinds
2528>>> import Generics.SOP (I(..))
2629>>> let example = I "foo" :* I pi :* Nil :: NP I '[String, Double]
2730>>> example
2831I "foo" :* I 3.141592653589793 :* Nil
32+```
2933
3034One thing Squeal uses `NP` for is to form lists of aliases,
3135using GHC's `OverloadedLabels` extension, hosting the names
3236of the aliases themselves at the type level.
3337
38+```Haskell
3439>>> :set -XKindSignatures -XOverloadedLabels -XFlexibleInstances -XMultiParamTypeClasses
3540>>> import GHC.TypeLits
3641>>> import GHC.OverloadedLabels
3742>>> data Alias (alias :: Symbol) = Alias deriving (Eq,Ord,Show)
3843>>> instance IsLabel label (Alias label) where fromLabel = Alias
3944>>> let aliases = #foo :* #bar :* Nil :: NP Alias '["foo", "bar"]
45+```
4046
4147However, it's very ugly to have to end every list with `:* Nil`.
42−When I announced the release of Squeal, people rightly [complained]
43−(https://www.reddit.com/r/haskell/comments/6yr5v6/announcing_squeal_a_deep_embedding_of_sql_in/dmq8vvn)
48+When I announced the release of Squeal, people rightly [complained](https://www.reddit.com/r/haskell/comments/6yr5v6/announcing_squeal_a_deep_embedding_of_sql_in/dmq8vvn)
4449about the syntactic noise. Luckily, there's a neat trick we can use to get rid of it.
4550Making an `IsLabel` instance not only for elements of our list
4651but also for lists of length 1, we can ask GHC to interpret
4752the last label as a list.
4853
54+```Haskell
4955>>> instance IsLabel label (NP Alias '[label]) where fromLabel = Alias :* Nil
5056>>> let aliases' = #foo :* #bar :: NP Alias '["foo", "bar"]
57+```
5158
52−Squeal now uses this trick with various type classes to eliminate all
53−need of using `Nil` in a list.
59+Version 0.3.1 of Squeal enables the "Scrap your Nils" trick for
60+heterogeneous lists of `Alias`es, `Aliased` expressions, `PGlabel`s and `By`s
61+with the typeclasses `IsLabel`, `IsQualified`, `Aliasable`, and `IsPGlabel`,
62+to eliminate all need of using `Nil` in a list.