Skip to content

Commit

Permalink
Fixing some partial function warnings being emitted by GHC.
Browse files Browse the repository at this point in the history
Replacing `tail` with a varient that emits an empty list when the input
list is also empty. Otherwise it behaves as `Prelude.tail`
  • Loading branch information
lepsa committed Apr 4, 2024
1 parent 6651529 commit 7ffb13e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
7 changes: 5 additions & 2 deletions Graphics/Implicit/Export/OutputFormat.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@ module Graphics.Implicit.Export.OutputFormat
)
where

import Prelude (Bool, Eq, FilePath, Maybe, Read (readsPrec), Show(show), String, drop, error, flip, length, tail, take, ($), (<>), (==))
import Prelude (Bool, Eq, FilePath, Maybe, Read (readsPrec), Show(show), String, drop, error, flip, length, take, ($), (<>), (==), snd)
import Control.Applicative ((<$>))
-- For making the format guesser case insensitive when looking at file extensions.
import Data.Char (toLower)
import Data.Default.Class (Default(def))
import Data.List (lookup, elem)
import Data.List (lookup, elem, uncons)
import Data.Maybe (fromMaybe)
import Data.Tuple (swap)
-- For handling input/output files.
import System.FilePath (takeExtensions)

tail :: [a] -> [a]
tail l = fromMaybe [] $ snd <$> uncons l

-- | A type serving to enumerate our output formats.
data OutputFormat
= SVG
Expand Down
6 changes: 5 additions & 1 deletion Graphics/Implicit/Export/Render.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
-- export getContour and getMesh, which returns the edge of a 2D object, or the surface of a 3D object, respectively.
module Graphics.Implicit.Export.Render (getMesh, getContour) where

import Prelude(error, (-), ceiling, ($), (+), (*), max, div, tail, fmap, reverse, (.), foldMap, min, Int, (<>), (<$>), traverse)
import Prelude(error, (-), ceiling, ($), (+), (*), max, div, fmap, reverse, (.), foldMap, min, Int, (<>), (<$>), traverse, snd)

import Graphics.Implicit.Definitions (, , Fastℕ, ℝ2, ℝ3, TriangleMesh, Obj2, SymbolicObj2, Obj3, SymbolicObj3, Polyline(getSegments), (⋯/), fromℕtoℝ, fromℕ, ℝ3' (ℝ3'))

Expand Down Expand Up @@ -71,10 +71,14 @@ import Graphics.Implicit.Export.Render.HandlePolylines (cleanLoopsFromSegs)
import Data.Maybe (fromMaybe)
import Graphics.Implicit.Primitives (getImplicit)
import Control.Lens (_Wrapped, view, over, _Just)
import Data.List (uncons)

-- Set the default types for the numbers in this file.
default (, Fastℕ, )

tail :: [a] -> [a]
tail l = fromMaybe [] $ snd <$> uncons l

getMesh :: ℝ3 -> SymbolicObj3 -> TriangleMesh
getMesh res@(V3 xres yres zres) symObj =
let
Expand Down
8 changes: 6 additions & 2 deletions Graphics/Implicit/Export/Render/TesselateLoops.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@

module Graphics.Implicit.Export.Render.TesselateLoops (tesselateLoop) where

import Prelude(sum, (-), pure, ($), length, (==), zip, init, tail, reverse, (<), (/), null, (<>), head, (*), abs, (+), foldMap, (&&))
import Prelude(sum, (-), pure, ($), length, (==), zip, init, reverse, (<), (/), null, (<>), head, (*), abs, (+), foldMap, (&&), snd, (<$>))

import Graphics.Implicit.Definitions (, , Obj3, ℝ3, TriangleMesh(TriangleMesh), Triangle(Triangle))

import Graphics.Implicit.Export.Render.Definitions (TriSquare(Tris))

import Graphics.Implicit.Export.Util (centroid)

import Data.List (genericLength)
import Data.List (genericLength, uncons)
import Linear ( cross, Metric(norm), (^*), (^/) )
import Data.Maybe (fromMaybe)

tail :: [a] -> [a]
tail l = fromMaybe [] $ snd <$> uncons l

-- de-compose a loop into a series of triangles or squares.
-- FIXME: res should be ℝ3.
Expand Down
7 changes: 6 additions & 1 deletion programs/docgen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
-- FIXME: document why we need each of these.
{-# LANGUAGE ScopedTypeVariables #-}

import Prelude(IO, Show, String, Int, Maybe(Just,Nothing), Eq, return, ($), show, fmap, (<>), putStrLn, filter, zip, null, undefined, const, Bool(True,False), fst, (.), head, tail, length, (/=), (+), error, print)
import Prelude(IO, Show, String, Int, Maybe(Just,Nothing), Eq, return, ($), show, fmap, (<>), putStrLn, filter, zip, null, undefined, const, Bool(True,False), fst, (.), head, length, (/=), (+), error, print, snd, (<$>))
import Data.Maybe (fromMaybe)
import Data.List (uncons)
import Graphics.Implicit.ExtOpenScad.Primitives (primitiveModules)
import Graphics.Implicit.ExtOpenScad.Definitions (ArgParser(AP,APFail,APExample,APTest,APTerminator,APBranch), Symbol(Symbol), OVal(ONModule), SourcePosition(SourcePosition), StateC)

Expand All @@ -13,6 +15,9 @@ import Control.Monad (forM_)
import Data.Traversable (traverse)
import Data.Text.Lazy (unpack, pack)

tail :: [a] -> [a]
tail l = fromMaybe [] $ snd <$> uncons l

-- | Return true if the argument is of type ExampleDoc.
isExample :: DocPart -> Bool
isExample (ExampleDoc _ ) = True
Expand Down

0 comments on commit 7ffb13e

Please sign in to comment.