ShowF (empty) → 0.1.0
raw patch · 4 files changed
+103/−0 lines, 4 filesdep +basesetup-changed
Dependencies added: base
Files
- COPYING +25/−0
- Setup.lhs +3/−0
- ShowF.cabal +25/−0
- src/Text/ShowF.hs +50/−0
+ COPYING view
@@ -0,0 +1,25 @@+Copyright (c) 2012 Conal Elliott+All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions+are met:+1. Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.+2. 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.+3. The names of the authors may not be used to endorse or promote products+ derived from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``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 AUTHORS 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.lhs view
@@ -0,0 +1,3 @@+#!/usr/bin/env runhaskell+> import Distribution.Simple+> main = defaultMain
+ ShowF.cabal view
@@ -0,0 +1,25 @@+Name: ShowF+Version: 0.1.0+Cabal-Version: >= 1.6+Synopsis: Show for * -> *+Category: Text+Description: Provides a Show-like class for * -> *+Author: Conal Elliott+Maintainer: conal@conal.net+Copyright: (c) 2013 by Conal Elliott+License: BSD3+License-File: COPYING+Stability: experimental+build-type: Simple++source-repository head+ type: git+ location: git://github.com/conal/ShowF.git++Library+ hs-Source-Dirs: src+ Extensions:+ Build-Depends: base<5+ Exposed-Modules: + Text.ShowF+ ghc-options: -Wall
+ src/Text/ShowF.hs view
@@ -0,0 +1,50 @@+-- {-# LANGUAGE #-}+{-# OPTIONS_GHC -Wall #-}++-- {-# OPTIONS_GHC -fno-warn-unused-imports #-} -- TEMP+-- {-# OPTIONS_GHC -fno-warn-unused-binds #-} -- TEMP++----------------------------------------------------------------------+-- |+-- Module : Text.ShowF+-- Copyright : (c) Conal Elliott+-- +-- Maintainer : conal@conal.net+-- Stability : experimental+-- +-- Showable functors+----------------------------------------------------------------------++module Text.ShowF where++import Data.Functor ((<$>))++-- TODO: explicit exports++class ShowF f where+ showF :: Show a => f a -> String+ showsPrecF :: Show a => Int -> f a -> ShowS+ showsPrecF _ x s = showF x ++ s+ showF x = showsF x ""++newtype WrapShowF f a = WrapShowF (f a)++instance (ShowF f, Show a) => Show (WrapShowF f a) where+ showsPrec p (WrapShowF fa) = showsPrecF p fa++showsF :: (ShowF f, Show a) => f a -> ShowS+showsF = showsPrecF 0++showsApp1 :: Show a => String -> Int -> a -> ShowS+showsApp1 s p a = strApp1 s p (showsPrec 11 a)++showsFApp1 :: (ShowF f, Show a) => String -> Int -> f a -> ShowS+showsFApp1 s p fa = strApp1 s p (showsPrecF 11 fa)++showsFComp1 :: (Functor g, ShowF g, ShowF f, Show a) => String -> Int -> g (f a) -> ShowS+showsFComp1 s p gfa = showsFApp1 s p (WrapShowF <$> gfa)++strApp1 :: String -> Int -> ShowS -> ShowS+strApp1 s p sh = showParen (p >= 11) $ showString s . showChar ' ' . sh++-- To do: Refactor more elegantly?