From eb5c8b4e2944d7f4137538c39e5e2be915267d85 Mon Sep 17 00:00:00 2001 From: Yoo Chung Date: Mon, 21 Oct 2024 19:06:14 -0400 Subject: [PATCH] Do not require a type class for `withFallback`. There may come a day when `withFallback` should be used with another type of value in the `Clay.Geometry` module, but until then, it is overkill to use a type class. --- src/Clay/Geometry.hs | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/src/Clay/Geometry.hs b/src/Clay/Geometry.hs index 68af3d1..ab70618 100644 --- a/src/Clay/Geometry.hs +++ b/src/Clay/Geometry.hs @@ -132,26 +132,16 @@ aspectRatio = key "aspect-ratio" -- The same as the normal % operator. infixl 7 % --- | A type class for which a type can have a value with another value as a fallback. --- Basically, a type class for types which can use 'withFallback'. --- --- 'withFallback' was defined for 'AspectRatio', but this is a type class --- because 'withFallback' is a generic name which we may want to reuse --- for other types in the future. -class WithFallback a where - -- | Returns a value where one value has another value as a fallback. - -- - -- * For 'AspectRatio', it can be used to specify that the intrinsic aspect - -- ratio should be used, but a fixed ratio can be used as a fallback. - withFallback :: a -> a -> a - -instance WithFallback AspectRatio where - withFallback x@(AspectRatioValue "auto") y@(AspectRatio _) = - AspectRatioWithFallback (x, y) - withFallback x@(AspectRatio _) y@(AspectRatioValue "auto") = - AspectRatioWithFallback (x, y) - withFallback _ _ = - error "Arguments for aspectRatio . withFallback must be auto and a ratio in either order" +-- | Returns an aspect ratio specifying that the intrinsic aspect +-- ratio should be used, but when it is unknown or there is none, +-- a fixed ratio can be used as a fallback. +withFallback :: AspectRatio -> AspectRatio -> AspectRatio +withFallback x@(AspectRatioValue "auto") y@(AspectRatio _) = + AspectRatioWithFallback (x, y) +withFallback x@(AspectRatio _) y@(AspectRatioValue "auto") = + AspectRatioWithFallback (x, y) +withFallback _ _ = + error "Arguments for aspectRatio . withFallback must be auto and a ratio in either order" -------------------------------------------------------------------------------