Skip to content

Instantly share code, notes, and snippets.

@LeviSchuck
Created September 21, 2013 05:55
Show Gist options
  • Save LeviSchuck/6647627 to your computer and use it in GitHub Desktop.
Save LeviSchuck/6647627 to your computer and use it in GitHub Desktop.
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
-- This example is known to be incomplete...
import qualified Solar.Data.KV as K
import Solar.Storage.FS as FS
import Solar.Storage as St
import Data.Map as Map
import Data.Dynamic as D
import qualified Data.ByteString.Lazy.UTF8 as U
import Text.Read(readMaybe)
import qualified Data.ByteString.Lazy as BL
-- ....
kvToBS :: (Show n, Show r, Show c, Show (d n r c), Show (c' n r c))
=> K.KV n r c d c'
-> BL.ByteString
kvToBS kv =
U.fromString $ show kv
kvFromBS :: (Read n, Read r, Read c, Read (d n r c), Read (c' n r c))
=> BL.ByteString
-> Maybe (K.KV n r c d c')
kvFromBS b = readMaybe $ U.toString $ b
fs = FSMethod
{ fsExt = "txt"
, fsRead = kvFromBS
, fsWrite = kvToBS
}
path = KFilePath "/tmp"
cont = Map.insert (typeOf path) (toDyn path) noContext
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment