Skip to content

Commit 458ae00

Browse files
committed
Common.Array: rewrite documentation
1 parent 6672905 commit 458ae00

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

src/Language/Fortran/Common/Array.hs

+19-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{-# LANGUAGE UndecidableInstances #-} -- due to instance design :)
1+
{-# LANGUAGE UndecidableInstances #-} -- required due to instance design
22

33
module Language.Fortran.Common.Array where
44

@@ -19,7 +19,8 @@ data Dim a = Dim
1919
deriving stock (Functor, Foldable, Traversable)
2020
deriving anyclass (NFData, Binary)
2121

22-
-- | Meaningless instance, only use transparently.
22+
-- | This instance is purely for convenience. No definition of ordering is
23+
-- provided, and the implementation may change at any time.
2324
deriving stock Ord
2425

2526
-- | Fortran syntax uses @lower:upper@, so only provide an 'Out' instance for
@@ -32,19 +33,22 @@ instance Out (Dim a) => F.Pretty (Dim a) where
3233

3334
-- | Evaluated dimensions of a Fortran array.
3435
--
35-
-- Syntactic datatype; includes lower bound. (Normalized arrays only require the
36-
-- extent.) Also, since Fortran array dimensions can be defined in two ways
37-
-- (@lower:upper@, or @lower@ and dimension extent) but share representation, a
38-
-- type-level switch is included for distinguishing between them.
36+
-- A known-length dimension is defined by a lower bound and an upper bound. This
37+
-- data type takes a syntactic view, rather than normalizing lower bound to 0
38+
-- and passing just dimension extents.
3939
--
40-
-- Extremely general. You select the list type @t@ (which should be 'Foldable')
41-
-- and the numeric index type @a@ (e.g. 'Int'). The intent is that this type may
42-
-- be quietly wrapped into others with type synonyms and perhaps pattern
43-
-- synonyms.
40+
-- You select the list type @t@ (which should be 'Functor', 'Foldable' and
41+
-- 'Traversable') and the numeric index type @a@ (e.g. 'Int').
4442
--
45-
-- For soundness, consider using a non-empty list type.
43+
-- Note that using a non-empty list type such as 'Data.List.NonEmpty.NonEmpty'
44+
-- will disallow representing zero-dimension arrays, which may be useful for
45+
-- soundness.
4646
--
47-
-- 'DimensionType' only matters for explicit and assumed-size (the tuples).
47+
-- Note the following excerpt from the F2018 standard (8.5.8.2 Explicit-shape
48+
-- array):
49+
--
50+
-- > If the upper bound is less than the lower bound, the range is empty, the
51+
-- > extent in that dimension is zero, and the array is of zero size.
4852
data Dims t a
4953
= DimsExplicitShape
5054
(t (Dim a)) -- ^ list of all dimensions
@@ -61,7 +65,7 @@ data Dims t a
6165
deriving stock (Generic)
6266
deriving stock (Functor, Foldable, Traversable)
6367

64-
-- We have to standalone derive most instances due to @t (a, a)@.
68+
-- We have to standalone derive most instances due to the @t@ list-like.
6569
deriving stock instance (Show a, Show (t a), Show (t (Dim a)))
6670
=> Show (Dims t a)
6771
deriving anyclass instance (NFData a, NFData (t a), NFData (t (Dim a)))
@@ -73,7 +77,8 @@ deriving stock instance (Eq a, Eq (t a), Eq (t (Dim a)))
7377
deriving anyclass instance (Binary a, Binary (t a), Binary (t (Dim a)))
7478
=> Binary (Dims t a)
7579

76-
-- | Meaningless instance, only use transparently.
80+
-- | This instance is purely for convenience. No definition of ordering is
81+
-- provided, and the implementation may change at any time.
7782
deriving stock instance (Ord a, Ord (t a), Ord (t (Dim a)))
7883
=> Ord (Dims t a)
7984

0 commit comments

Comments
 (0)