packages feed

hyper (empty) → 0.1.0.0

raw patch · 5 files changed

+155/−0 lines, 5 filesdep +basedep +blaze-htmldep +deepseqsetup-changed

Dependencies added: base, blaze-html, deepseq, text

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2016 Heinrich Apfelmus++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Heinrich Apfelmus nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ hyper.cabal view
@@ -0,0 +1,30 @@+Name:               hyper+Version:            0.1.0.0+Synopsis:           Display class for the HyperHaskell graphical Haskell interpreter+Description:+  This package is part of the /HyperHaskell/ project and provides+  the @Display@ class for visualizing and pretty printing Haskell values.+  .+Category:           Graphics, Pretty Printer+License:            BSD3+License-file:       LICENSE+Author:             Heinrich Apfelmus+Maintainer:         Heinrich Apfelmus <apfelmus quantentunnel de>+Copyright:          (c) Heinrich Apfelmus 2016++Cabal-version:      >= 1.8+Build-type:         Simple++Source-repository head+    type:               git+    location:           git://github.com/HeinrichApfelmus/hyper-haskell.git+    subdir:             haskell/hyper/++Library+    hs-source-dirs:     src+    build-depends:      base         >= 4.6   && < 4.10+                        , deepseq    >= 1.2   && < 1.5+                        , blaze-html >= 0.7   && < 0.9+                        , text       >= 0.11  && < 1.3+    exposed-modules:    Hyper+                        , Hyper.Internal
+ src/Hyper.hs view
@@ -0,0 +1,16 @@+{-# LANGUAGE FlexibleInstances #-}+module Hyper (+    -- * Synopsis+    -- | Visualizing and representing Haskell values in the HyperHaskell interpreter.+    +    -- * Graphics+    Graphic, string, html,+    +    -- * Display class+    Display(..),+    +    -- * Internal+    displayIO,+    ) where++import Hyper.Internal
+ src/Hyper/Internal.hs view
@@ -0,0 +1,77 @@+{-# LANGUAGE FlexibleInstances, OverlappingInstances, UndecidableInstances #-}+{-# LANGUAGE DeriveDataTypeable #-}+module Hyper.Internal (+    -- * Synopsis+    -- | Internal data types used by the HyperHaskell back-end+    -- to analyze values constructed with the 'Hyper' module.+    +    -- * Documentation+    Graphic(..), string, html,+    Display(..),+    displayIO,+    ) where++import           Control.DeepSeq+import           Data.List            (isPrefixOf)+import           Data.Typeable++import qualified Data.Text       as T+import qualified Data.Text.Lazy  as TL+import qualified Text.Blaze.Html as H+import qualified Text.Blaze.Html.Renderer.Text as H++{-----------------------------------------------------------------------------+    Graphics+------------------------------------------------------------------------------}+-- | A graphical representation of data.+data Graphic = Graphic { gHtml :: T.Text } deriving (Typeable)++instance NFData Graphic where rnf g = rnf (gHtml g)++-- | Render a 'String' as a 'Graphic'.+string :: String -> Graphic+string = Graphic . TL.toStrict . H.renderHtml . H.toHtml++-- | Render arbitrary HTML code as a 'Graphic'.+-- +-- NOTE: This function does not do check whether the input is well-formed HTML.+--+-- NOTE: This function will probably deprecated once we figure out+-- how to do this properly, but for now, just use it.+html :: T.Text -> Graphic+html = Graphic++{-----------------------------------------------------------------------------+    Display class+------------------------------------------------------------------------------}+-- | Class for displaying Haskell values.+class Display a where+    display :: a -> Graphic++instance Display ()           where display x = x `seq` fromShow x+instance Display Graphic      where display = id+instance Display Bool         where display = fromShow+instance Display Double       where display = fromShow+instance Display Integer      where display = fromShow+instance Display Int          where display = fromShow+instance Display String       where display = fromShow+instance Display [Int]        where display = displayList+instance Display [String]     where display = displayList++fromShow :: Show a => a -> Graphic+fromShow = string . show++displayList :: Show a => [a] -> Graphic+displayList = fromShow++{-----------------------------------------------------------------------------+    Internal Class for displaying either IO actions or values+------------------------------------------------------------------------------}+class DisplayIO a where+    displayIO :: a -> IO Graphic++instance Display a => DisplayIO (IO a) where+    displayIO = fmap display+instance Display a => DisplayIO a where+    displayIO = return . display+