on master help sign in
Add binary instance to non-empty lists
commit184b14c64f9ad0c36a82c9031649bf528f75b816 authorEvan Czaplicki <evancz@users.noreply.github.com> dateThu 2 May 2019, 13:43 (7 years ago) parent7b60982
1 file changed+11
compiler/src/Data/NonEmptyList.hs+11
compiler/src/Data/NonEmptyList.hs+11
@@ -6,6 +6,8 @@ module Data.NonEmptyList
66 where
77
88
9+import Control.Monad (liftM2)
10+import Data.Binary (Binary, get, put)
911import qualified Data.List as List
1012
1113
@@ -55,3 +57,12 @@ sortBy comparison (List x xs) =
5557 LT -> List x (y:ys)
5658 EQ -> List x (y:ys)
5759 GT -> List y (List.insertBy comparison x ys)
60+
61+
62+
63+-- BINARY
64+
65+
66+instance (Binary a) => Binary (List a) where
67+ put (List x xs) = put x >> put xs
68+ get = liftM2 List get get