1
- {-# LANGUAGE UndecidableInstances #-} -- due to instance design :)
1
+ {-# LANGUAGE UndecidableInstances #-} -- required due to instance design
2
2
3
3
module Language.Fortran.Common.Array where
4
4
@@ -19,7 +19,8 @@ data Dim a = Dim
19
19
deriving stock (Functor , Foldable , Traversable )
20
20
deriving anyclass (NFData , Binary )
21
21
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.
23
24
deriving stock Ord
24
25
25
26
-- | 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
32
33
33
34
-- | Evaluated dimensions of a Fortran array.
34
35
--
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.
39
39
--
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').
44
42
--
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.
46
46
--
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.
48
52
data Dims t a
49
53
= DimsExplicitShape
50
54
(t (Dim a )) -- ^ list of all dimensions
@@ -61,7 +65,7 @@ data Dims t a
61
65
deriving stock (Generic )
62
66
deriving stock (Functor , Foldable , Traversable )
63
67
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 .
65
69
deriving stock instance (Show a , Show (t a ), Show (t (Dim a )))
66
70
=> Show (Dims t a )
67
71
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)))
73
77
deriving anyclass instance (Binary a , Binary (t a ), Binary (t (Dim a )))
74
78
=> Binary (Dims t a )
75
79
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.
77
82
deriving stock instance (Ord a , Ord (t a ), Ord (t (Dim a )))
78
83
=> Ord (Dims t a )
79
84
0 commit comments