Skip to content

Commit

Permalink
add compose
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeplus64 committed Dec 14, 2012
1 parent 82954fb commit fb11a30
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion record.cabal
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,5 @@
name: record name: record
version: 0.1.0.50 version: 0.1.0.52
synopsis: Efficient, type safe records implemented using GADTs and type level strings. synopsis: Efficient, type safe records implemented using GADTs and type level strings.
homepage: http://quasimal.com/projects/records homepage: http://quasimal.com/projects/records
license: BSD3 license: BSD3
Expand Down
11 changes: 11 additions & 0 deletions src/Data/Record.hs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ module Data.Record ( key
, alter , alter
, append , append
, Record , Record
, compose
, decompose
, (:.)
, P , P
, (:=) , (:=)
, type (++) , type (++)
Expand All @@ -39,6 +42,8 @@ module Data.Record ( key
import Language.Haskell.TH.Syntax import Language.Haskell.TH.Syntax
import Language.Haskell.TH.Quote import Language.Haskell.TH.Quote
import Language.Haskell.TH.Lib 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, -- | 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 -- you can't do field access from a string and a Typeable context, although
Expand Down Expand Up @@ -74,6 +79,12 @@ type family Wrap (w :: a) x
type instance Wrap (w :: * -> *) x = w x type instance Wrap (w :: * -> *) x = w x
type instance Wrap P x = 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 data Record w r where
C :: Wrap w e -> Record w r -> Record w (k := e ': r) C :: Wrap w e -> Record w r -> Record w (k := e ': r)
E :: Record w '[] E :: Record w '[]
Expand Down
17 changes: 17 additions & 0 deletions src/Example.hs
Original file line number Original file line Diff line number Diff line change
@@ -1,2 +1,19 @@
{-# LANGUAGE TypeOperators, DataKinds, QuasiQuotes #-} {-# 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"



0 comments on commit fb11a30

Please sign in to comment.