Advertisement
NLinker

Interactive GHCi helper for custom monad

Nov 9th, 2019
601
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- https://github.com/tweag/HaskellR/blob/master/inline-r/src/H/Prelude/Interactive.hs
  2.  
  3. -- |
  4. -- Copyright: (C) 2013 Amgen, Inc.
  5. --
  6. -- This class is not meant to be imported in any other circumstance than in
  7. -- a GHCi session.
  8.  
  9. {-# LANGUAGE TypeFamilies #-}
  10.  
  11. {-# OPTIONS_GHC -fno-warn-orphans #-}
  12. module H.Prelude.Interactive
  13.   ( module H.Prelude
  14.   , PrintR(..)
  15.   , p
  16.   , printQuote
  17.   )
  18.   where
  19.  
  20. import qualified Foreign.R as R
  21. import H.Prelude hiding (withEmbeddedR)
  22.  
  23. instance MonadR IO where
  24.   io = id
  25.   data ExecContext IO = ExecContext
  26.   getExecContext = return ExecContext
  27.   unsafeRunWithExecContext = const
  28.  
  29. class PrintR a where
  30.   printR :: MonadR m => a -> m ()
  31.  
  32. instance PrintR (SEXP s a) where
  33.   printR = io . R.printValue
  34.  
  35. instance PrintR (R.SomeSEXP s) where
  36.   printR s = R.unSomeSEXP s printR
  37.  
  38. -- | A form of the 'printR' function that is more convenient in an interactive
  39. -- session.
  40. p :: (MonadR m, PrintR a) => m a -> m ()
  41. p = (>>= printR)
  42.  
  43. -- | A form of the 'printR' function that is more convenient in an interactive
  44. -- session.
  45. {-# DEPRECATED printQuote "Use 'p' instead." #-}
  46. printQuote :: (MonadR m, PrintR a) => m a -> m ()
  47. printQuote = p
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement