https://chat.openai.com/chat?model=gpt-4
User:
Propose a meaningful implementation of a Haskell function of type f :: (a → (Maybe a, b)) → a → [b]
ChatGPT:
| {-# LANGUAGE AllowAmbiguousTypes #-} | |
| {-# LANGUAGE DataKinds #-} | |
| {-# LANGUAGE InstanceSigs #-} | |
| {-# LANGUAGE KindSignatures #-} | |
| {-# LANGUAGE MultiParamTypeClasses #-} | |
| {-# LANGUAGE PolyKinds #-} | |
| {-# LANGUAGE RankNTypes #-} | |
| {-# LANGUAGE StandaloneKindSignatures #-} | |
| {-# LANGUAGE TypeApplications #-} | |
| {-# LANGUAGE TypeFamilies #-} |
| {-# LANGUAGE | |
| DataKinds, | |
| DeriveGeneric, | |
| PolyKinds, | |
| StandaloneDeriving, | |
| TypeFamilies, | |
| UndecidableInstances #-} | |
| module T where | |
| import Data.Kind (Constraint, Type) |
| -- Written by Eitan Chatav, cleaned up by me | |
| {-# language GADTs #-} | |
| import Type.Reflection | |
| import Data.Constraint | |
| data U_Expr | |
| = U_Bool Bool | |
| | U_Int Int |
| {- | |
| Examples: | |
| > reify @Int $ eval $ A (reflect (abs :: Int -> Int)) (I (-9)) | |
| 9 | |
| > reify @Int $ eval $ A (A (reflect ((*) :: Int -> Int -> Int)) (reflect @Int 3)) (reflect @Int 5) | |
| 15 |
Take a number, square it, the result is non-negative. Because positive * positive = positive and negative * negative is positive. Or
But someone wanted to take square roots of negative numbers, so they did, and called it 'i'.
The solution, to put imaginary and complex numbers on a solid foundation is something called a ring quotient. What you do is you start with the ring (meaning number system) of polynomials over the real numbers
-
$1, 2 3.5, \pi$ etc. -
$i, i^2, 0.3 + 9.5 i + 23 i^3$ and so on.
| {-# LANGUAGE ApplicativeDo #-} | |
| {-# LANGUAGE BlockArguments #-} | |
| {-# LANGUAGE DeriveFunctor #-} | |
| {-# LANGUAGE DerivingStrategies #-} | |
| {-# LANGUAGE GeneralizedNewtypeDeriving #-} | |
| {-# LANGUAGE UndecidableInstances #-} | |
| module HasCal where | |
| import Control.Applicative (Alternative(..), liftA2) |
| # This was only tested against revision ac2d18a7353cd3ac1ba4b5993f2776fe0c5eedc9 | |
| # of https://gitlab.haskell.org/ghc/ghc | |
| let | |
| nixpkgs = builtins.fetchTarball { | |
| url = "https://github.com/NixOS/nixpkgs/archive/7e003d7fb9eff8ecb84405360c75c716cdd1f79f.tar.gz"; | |
| sha256 = "08y8pmz7xa58mrk52nafgnnrryxsmya9qaab3nccg18jifs5gyal"; | |
| }; | |
| config.allowBroken = true; |