From 80d1737c7ca12d3338428553968b37e3f5c2de4a Mon Sep 17 00:00:00 2001 From: Alexander Foremny Date: Thu, 30 Nov 2023 04:02:11 +0100 Subject: chore: define `(._N)` accessors for tuples --- app/Tuple.hs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 app/Tuple.hs (limited to 'app/Tuple.hs') diff --git a/app/Tuple.hs b/app/Tuple.hs new file mode 100644 index 0000000..8b43279 --- /dev/null +++ b/app/Tuple.hs @@ -0,0 +1,20 @@ +{-# OPTIONS_GHC -fno-warn-orphans #-} + +module Tuple where + +import GHC.Records (HasField (..)) + +instance HasField "_1" (a, b) a where + getField (a, _) = a + +instance HasField "_2" (a, b) b where + getField (_, b) = b + +instance HasField "_1" (a, b, c) a where + getField (a, _, _) = a + +instance HasField "_2" (a, b, c) b where + getField (_, b, _) = b + +instance HasField "_3" (a, b, c) c where + getField (_, _, c) = c -- cgit v1.2.3