<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
span.gmailsignatureprefix
{mso-style-name:gmail_signature_prefix;}
span.EmailStyle20
{mso-style-type:personal-compose;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">Yes, will check on it.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">That is because the reason that a simple program was used was because the example was to ask GPT to solve it is a range of languages, one of which was Haskell and there were links to solutions in all of them..<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">“<b>Write binary search in <u>xxxx</u>. Ensure bug-free code by specifying preconditions, postconditions, invariants, variants, internal states.”</b><o:p></o:p></p>
<p class="MsoNormal" style="margin-left:.5in"><o:p> </o:p></p>
<p class="MsoNormal" style="margin-left:.5in"> { HTML, CSS and JavaScript, C++, Haskell, JavaScript, Python, CommonLisp, C, C#, PHP, Java, Go, Erlang, Alloy, TLA+, X-Machine, PVS Verifier, SPIN model checker, Guarded Command Language, Hoare triples, Gries
& Owicki concurrent code}<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">It was an interesting exercise from Dr. Nenad Koncar, a successful NL researcher and developer. I’ll ask him for a corrected link to the Haskell version.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div style="mso-element:para-border-div;border:solid windowtext 1.0pt;padding:1.0pt 0in 1.0pt 4.0pt;margin-left:40.5pt;margin-right:40.5pt">
<p class="MsoNormal" align="center" style="text-align:center;border:none;padding:0in">
<span style="font-size:16.0pt">Dr. Gregory Guthrie<o:p></o:p></span></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b>From:</b> Aloïs Cochard <alois.cochard@gmail.com> <br>
<b>Sent:</b> Saturday, April 1, 2023 8:23 AM<br>
<b>To:</b> Gregory Guthrie <guthrie@miu.edu><br>
<b>Cc:</b> haskell-cafe@haskell.org; Nenad Končar <nlpresearcher@gmail.com>; Haskell Community <replies+f6607596e3ee63f105e2b0327b86f062@discourse.haskell.org><br>
<b>Subject:</b> Re: [Haskell-cafe] GPT & Haskell<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">Dear Gregory,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Can you please fix your onecompiler vanity link? It points to the C++ runtime implementation.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Thanks<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">On Fri, 31 Mar 2023 at 22:04, Gregory Guthrie <<a href="mailto:guthrie@miu.edu">guthrie@miu.edu</a>> wrote:<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">From a colleague:<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> GPT Pretty smart(?!).<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">But this is of course simple, and searchable.<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Still…<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">--------------------------------------------------------------------------------------------------<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;margin-bottom:12.0pt">GPT-4 when prompted:<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><b>Write binary search in Haskel. Print results using putStrLn. Ensure bug-free code by specifying preconditions, postconditions, invariants, variants, internal states.</b><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;margin-bottom:12.0pt">gives the following response:<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><b>-- Binary search in Haskell<br>
-- Precondition: the list is sorted in ascending order<br>
-- Postcondition: the function returns the index of the target element if found, or Nothing otherwise<br>
-- Invariant: the search space is always within the bounds of the list<br>
-- Variant: the search space decreases by half at each recursive call<br>
-- Internal state: the lower and upper bounds of the search space<br>
<br>
binarySearch :: Ord a => [a] -> a -> Maybe Int<br>
binarySearch xs x = go xs x 0 (length xs - 1)<br>
where<br>
go xs x lo hi<br>
| lo > hi = Nothing -- base case: search space is empty<br>
| x == midElem = Just mid -- base case: target element is found<br>
| x < midElem = go xs x lo (mid - 1) -- recursive case: search in the left half<br>
| otherwise = go xs x (mid + 1) hi -- recursive case: search in the right half<br>
where<br>
mid = (lo + hi) `div` 2 -- calculate the middle index<br>
midElem = xs !! mid -- get the middle element<br>
<br>
-- Print results using putStrLn<br>
main :: IO ()<br>
main = do<br>
let xs = [1, 3, 5, 7, 9] -- a sorted list of integers<br>
let x = 5 -- a target element to search for<br>
let result = binarySearch xs x -- call the binary search function<br>
case result of -- pattern match on the result<br>
Nothing -> putStrLn "Element not found" -- print a message if Nothing is returned<br>
Just i -> putStrLn $ "Element found at index " ++ show i -- print a message with the index if Just i is returned</b><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;margin-bottom:12.0pt">The above code runs:<o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><b><a href="https://onecompiler.com/cpp/3z48yt2pp" target="_blank">https://onecompiler.com/cpp/3z48yt2pp</a></b><o:p></o:p></p>
</div>
</div>
<p class="MsoNormal">_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.<o:p></o:p></p>
</div>
</blockquote>
</div>
<p class="MsoNormal"><br clear="all">
<br>
<span class="gmailsignatureprefix">-- </span><o:p></o:p></p>
<div>
<div>
<div>
<div>
<div>
<p class="MsoNormal"><b>Λ\oïs</b><o:p></o:p></p>
</div>
<div>
<div>
<p class="MsoNormal"><a href="http://twitter.com/aloiscochard" target="_blank">http://twitter.com/aloiscochard</a><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><a href="http://github.com/aloiscochard" target="_blank">http://github.com/aloiscochard</a><o:p></o:p></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>