urbit/pkg/hs-urbit/lib/Data/Noun/Lens.hs
Benjamin Summers 2d25c21528 Jam: Cleanup
2019-07-01 19:43:10 -07:00

33 lines
937 B
Haskell

{-# LANGUAGE MagicHash #-}
module Data.Noun.Lens where
import ClassyPrelude
import Data.Noun.Pill
import Data.Noun
import Data.Noun.Atom
import Control.Lens
import Data.Noun.Jam.Fast (jam, jamBS)
import Data.Noun.Jam (cue)
--------------------------------------------------------------------------------
_CueBytes :: Prism' ByteString Noun
_CueBytes = prism' jamBS unJamBS
where unJamBS = preview (from pillBS . from pill . _Cue)
_Cue :: Prism' Atom Noun
_Cue = prism' jam cue
loadNoun :: FilePath -> IO (Maybe Noun)
loadNoun = fmap (preview $ from pillBS . from pill . _Cue) . readFile
dumpJam :: FilePath -> Noun -> IO ()
dumpJam fp = writeFile fp . view (re _Cue . pill . pillBS)
tryCuePill :: PillFile -> IO ()
tryCuePill pill =
loadNoun (show pill) >>= \case Nothing -> print "nil"
Just (Atom _) -> print "atom"
_ -> print "cell"