Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add compose

  • Loading branch information...
commit fb11a30944eadacbfeb14d1db3912d41c2611cbb 1 parent 82954fb
@mikeplus64 authored
Showing with 29 additions and 1 deletion.
  1. +1 −1  record.cabal
  2. +11 −0 src/Data/Record.hs
  3. +17 −0 src/Example.hs
View
2  record.cabal
@@ -1,5 +1,5 @@
name: record
-version: 0.1.0.50
+version: 0.1.0.52
synopsis: Efficient, type safe records implemented using GADTs and type level strings.
homepage: http://quasimal.com/projects/records
license: BSD3
View
11 src/Data/Record.hs
@@ -31,6 +31,9 @@ module Data.Record ( key
, alter
, append
, Record
+ , compose
+ , decompose
+ , (:.)
, P
, (:=)
, type (++)
@@ -39,6 +42,8 @@ module Data.Record ( key
import Language.Haskell.TH.Syntax
import Language.Haskell.TH.Quote
import Language.Haskell.TH.Lib
+import Control.Category ((.))
+import Prelude hiding ((.))
-- | A key of a record. This does not exist at runtime, and as a tradeoff,
-- you can't do field access from a string and a Typeable context, although
@@ -74,6 +79,12 @@ type family Wrap (w :: a) x
type instance Wrap (w :: * -> *) x = w x
type instance Wrap P x = x
+-- | Gross
+newtype (w :. m) x = Wmx { decompose :: w (m x) }
+
+compose :: (a -> w (m x)) -> a -> (w :. m) x
+compose f x = Wmx (f x)
+
data Record w r where
C :: Wrap w e -> Record w r -> Record w (k := e ': r)
E :: Record w '[]
View
17 src/Example.hs
@@ -1,2 +1,19 @@
{-# LANGUAGE TypeOperators, DataKinds, QuasiQuotes #-}
+import Data.Record
+import Data.IORef
+
+type Point
+ = '[ "x" := Double
+ , "y" := Double
+ , "z" := Double
+ , "colour" := (Int, Int, Int) ]
+
+op :: Record P Point
+op = 0 & 0 & 0 & (0,0,0) & end
+
+main :: IO ()
+main = do
+ let p = box (compose newIORef) op
+ print "yes"
+
Please sign in to comment.
Something went wrong with that request. Please try again.