Skip to content

Commit

Permalink
Add skeleton of the flat HLists
Browse files Browse the repository at this point in the history
  • Loading branch information
copumpkin committed Jun 26, 2014
1 parent 1ec25b7 commit f84130a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 9 deletions.
12 changes: 3 additions & 9 deletions shaped.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
-- Initial shaped.cabal generated by cabal init. For further
-- documentation, see http://haskell.org/cabal/users-guide/

name: shaped
version: 0.1.0.0
synopsis: Another flavor of generic programming
Expand All @@ -9,16 +6,13 @@ license: BSD3
license-file: LICENSE
author: Dan Peebles
maintainer: pumpkingod@gmail.com
-- copyright:
category: Data
build-type: Simple
-- extra-source-files:
cabal-version: >=1.10

library
exposed-modules: Data.Shaped, Data.Shaped.Generics, Data.Shaped.TH
-- other-modules:
exposed-modules: Data.Shaped, Data.Shaped.Generics, Data.Shaped.TH, Data.Shaped.Types, Data.Shaped.Product
other-extensions: GADTs, EmptyCase, MagicHash, DataKinds, PolyKinds, LambdaCase, ViewPatterns, TypeFamilies, DeriveGeneric, TypeOperators, KindSignatures, FlexibleContexts, FlexibleInstances, DefaultSignatures, ScopedTypeVariables, UndecidableInstances, ExistentialQuantification
build-depends: base >=4.7 && <4.8
build-depends: base >=4.7 && <4.8, ghc-prim
hs-source-dirs: src
default-language: Haskell2010
default-language: Haskell2010
41 changes: 41 additions & 0 deletions src/Data/Shaped/Product.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UnboxedTuples #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE FlexibleInstances #-}
module Data.Shaped.Product where

import GHC.Prim
import GHC.Types
import GHC.IO

-- This doesn't seem entirely worthless... worth coming up with a decent API for it
-- including perhaps how to actually construct these things... :)

type family Map (f :: a -> b) (xs :: [a]) :: [b] where
Map f '[] = '[]
Map f (x ': xs) = f x ': Map f xs

data Product (ts :: [*]) = Product (Array# Any)
data Elem (ts :: [*]) t = Elem Int#
data Length (ts :: [*]) = Length Int#

pget :: Product ts -> Elem ts t -> t
pget (Product arr#) (Elem i#) = case indexArray# arr# i# of (# x #) -> unsafeCoerce# x

plength :: Product ts -> Length ts
plength (Product arr#) = Length (sizeofArray# arr#)

pelems :: Product ts -> Product (Map (Elem ts) ts)
pelems = undefined





reallyUnsafeElem :: Int -> Elem ts t
reallyUnsafeElem (I# i#) = Elem i#

0 comments on commit f84130a

Please sign in to comment.