[Haskell-cafe] From records to a type class

Taru Karttunen taruti at taruti.net
Sat Jan 16 09:19:57 EST 2010


Excerpts from Stephen Tetley's message of Sat Jan 16 10:27:33 +0200 2010:
> If you haven't obviously got dispatch on type then records are certainly fine.

Yes, no dispatch on type.

I got a class based implementation compiling, but it seems overly
complex. Maybe the record approach is better after all.

This is a bit more complex than Parsec unfortunately. (an analogue
would be adding encodings to the types of Parsec parsers)


import Data.Word

data IsDir
data IsFile

type Ino  = Word32
data Attr = Attr {}
 
data Proxy t
type family FT (fht :: ((* -> *) -> *)) (fd :: *)
class FH (t :: (* -> *) -> *) where
    fhFre  :: Proxy t -> Word64 -> IO ()
    fhAllo :: forall any. FT t any -> IO Word64
    fhRe   :: forall any. Word64 -> IO (FT t any)

data UseRaw :: ((* -> *) -> *)
type instance FT UseRaw any = Word64
instance FH UseRaw where
   fhFre _ _ = return ()
   fhAllo    = return
   fhRe      = return

data UseStablePtr :: (* -> *) -> (* -> *) -> *
type instance FT (UseStablePtr ty) fh = ty fh
instance FH (UseStablePtr ty) where -- omitted

class FH (FhImpl ty) => Fuse' ty where
      type FhImpl ty :: (* -> *) -> *
      open'          :: ty -> Ino -> IO (FT (FhImpl ty) IsFile)
      read'          :: ty -> Ino -> FT (FhImpl ty) IsFile -> Word64  -> Word32 -> IO [Word8]
      opendir'       :: ty -> Ino -> IO (FT (FhImpl ty) IsDir)
      getattr'       :: forall fileOrDir. ty -> Ino -> FT (FhImpl ty) fileOrDir -> IO Attr

data MyUserType = MyUserType
instance Fuse' MyUserType where
  type FhImpl MyUserType = UseRaw
  open' = \_ _ -> return 22


- Taru Karttunen


More information about the Haskell-Cafe mailing list