Re: HasCallStack constraint for maximum in Prelude?

Todd Wilson via Haskell-Cafe <[email protected]> Sun, 22 Mar 2026 16:48:48 -0700
Newsgroups gmane.comp.lang.haskell.cafe
Message-ID <CA+-99oKtoLK-pj4BOov14Dc9-Zp=4-=xS91tdgBdP1Cj21wqsQ@mail.gmail.com>
--===============0406845475141008311==
Content-Type: multipart/alternative; boundary="000000000000eca0e9064da58f0a"

--000000000000eca0e9064da58f0a
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

I sent this two months ago but received no response. One of my students
asked me this, and I didn't know how to answer, so I asked here. Did it
slip in under the radar? Did I ask it in the wrong forum? Or was everyone
waiting for someone else to answer? :-)

Todd Wilson
Department of Computer Science
California State University, Fresno

On Sat, Jan 24, 2026 at 1:22=E2=80=AFPM Todd Wilson <[email protected]>=
 wrote:

> Should maximum and minimum have HasCallStack constraints like head and
> tail do?
>
> ghci> :type head
> head :: GHC.Stack.Types.HasCallStack =3D> [a] -> a
> ghci> head []
> *** Exception: Prelude.head: empty list
> CallStack (from HasCallStack):
>   error, called at libraries/base/GHC/List.hs:1646:3 in base:GHC.List
>   errorEmptyList, called at libraries/base/GHC/List.hs:85:11 in
> base:GHC.List
>   badHead, called at libraries/base/GHC/List.hs:81:28 in base:GHC.List
>   head, called at <interactive>:8:1 in interactive:Ghci1
> ghci> :type maximum
> maximum :: (Foldable t, Ord a) =3D> t a -> a
> ghci> maximum []
> *** Exception: Prelude.maximum: empty list
> CallStack (from HasCallStack):
>   error, called at libraries/base/GHC/List.hs:1646:3 in base:GHC.List
>   errorEmptyList, called at libraries/base/GHC/List.hs:717:28 in
> base:GHC.List
>   maximum, called at libraries/base/Data/Foldable.hs:745:15 in
> base:Data.Foldable
>
> Todd Wilson
>

--000000000000eca0e9064da58f0a
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr">I sent this two months ago but received n=
o response. One of my students asked me this, and I didn&#39;t know how to =
answer, so I asked here. Did it slip in under the radar? Did I ask it in th=
e wrong forum? Or was everyone waiting for someone else to answer? :-)<div>=
<div><br clear=3D"all"></div><div><div dir=3D"ltr" class=3D"gmail_signature=
"><div dir=3D"ltr">Todd Wilson<div>Department of Computer Science</div><div=
>California State University, Fresno</div></div></div></div></div></div><br=
><div class=3D"gmail_quote gmail_quote_container"><div dir=3D"ltr" class=3D=
"gmail_attr">On Sat, Jan 24, 2026 at 1:22=E2=80=AFPM Todd Wilson &lt;<a hre=
f=3D"mailto:[email protected]">[email protected]</a>&gt; wrote:<br>=
</div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;b=
order-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr"><d=
iv>Should maximum and minimum have HasCallStack constraints like head and t=
ail do?</div><div><br></div>ghci&gt; :type head<br>head :: GHC.Stack.Types.=
HasCallStack =3D&gt; [a] -&gt; a<br>ghci&gt; head []<br>*** Exception: Prel=
ude.head: empty list<br>CallStack (from HasCallStack):<br>=C2=A0 error, cal=
led at libraries/base/GHC/List.hs:1646:3 in base:GHC.List<br>=C2=A0 errorEm=
ptyList, called at libraries/base/GHC/List.hs:85:11 in base:GHC.List<br>=C2=
=A0 badHead, called at libraries/base/GHC/List.hs:81:28 in base:GHC.List<br=
>=C2=A0 head, called at &lt;interactive&gt;:8:1 in interactive:Ghci1<br>ghc=
i&gt; :type maximum<br>maximum :: (Foldable t, Ord a) =3D&gt; t a -&gt; a<b=
r>ghci&gt; maximum []<br>*** Exception: Prelude.maximum: empty list<br>Call=
Stack (from HasCallStack):<br>=C2=A0 error, called at libraries/base/GHC/Li=
st.hs:1646:3 in base:GHC.List<br>=C2=A0 errorEmptyList, called at libraries=
/base/GHC/List.hs:717:28 in base:GHC.List<br>=C2=A0 maximum, called at libr=
aries/base/Data/Foldable.hs:745:15 in base:Data.Foldable<br><div><br></div>=
<div>Todd Wilson</div></div>
</blockquote></div></div>

--000000000000eca0e9064da58f0a--

--===============0406845475141008311==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Haskell-Cafe mailing list -- [email protected]
To (un)subscribe, modify options or view archives go to:
Only members subscribed via the mailman list are allowed to post.
--===============0406845475141008311==--