{"id":530,"date":"2022-08-30T15:02:53","date_gmt":"2022-08-30T15:02:53","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/problem-about-ghci-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:02:53","modified_gmt":"2022-08-30T15:02:53","slug":"problem-about-ghci-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/problem-about-ghci-collection-of-common-programming-errors\/","title":{"rendered":"problem about ghci-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/5b15ac856b808e329185b1f653805d09?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nMatt Fenwick<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/2365756407af40c28c05d4d30182dbac?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nartella<br \/>\nhaskell ghc ghci winghci<br \/>\nQuestion 1Hi, if in WinGHCi I intentionally do the following wrong piece of code : 3 4Then the error message I get is :1:1:No instance for (Num (a0 -&gt; t0))arising from the literal `3&#8217;Possible fix: add an instance declaration for (Num (a0 -&gt; t0))In the expression: 3In the expression: 3 4In an equation for `it&#8217;: it = 3 4What exactly does No instance for (Num (a0 -&gt; t0)) mean?Question 2Why does the following piece of code : (+) 2 3 4 :1:7:No<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/f43dd9a92b5b5a39df4610b01511bdd1?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nuser42179<br \/>\nhaskell ghci<br \/>\nGHCI seems to cache the results of functions during an interactive session. It&#8217;s easy to notice, j<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/9ee895c4ad3fa29cf3aaa4abddda289f?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\npyrospade<br \/>\nhaskell multiline ghci<br \/>\nI like to parse strings ad hoc in Python by just pasting into the interpreter.&gt;&gt;&gt; s = &#8220;&#8221;&#8221;Adams, John &#8230; Washington,George &#8230; Lincoln,Abraham &#8230; Jefferson, Thomas &#8230; &#8220;&#8221;&#8221; &gt;&gt;&gt; print &#8220;\\n&#8221;.join(x.split(&#8220;,&#8221;)[1].replace(&#8221; &#8220;, &#8220;&#8221;)for x in s.strip().split(&#8220;\\n&#8221;)) John George Abraham ThomasThis works great using the Python interpreter, but I&#8217;d like to do this with Haskell\/GHCi. Problem is, I can&#8217;t paste multi-line strings. I can use getContents with an EOF character, but I can only do it once since the EO<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/c214754fba6f3a238a93af85a0ab4f58?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nAndrewC<br \/>\nhaskell ghci<br \/>\nI wrote the below code to construct a tree with given vertex given a list of connections between vertices.type Connection = (Int,Int) data Tree = Leaf Int | Node Int [Tree] deriving (Eq,Read,Show)makeTree :: Int -&gt; [Connection] -&gt; Tree makeTree x [] = Leaf x makeTree indx con<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/d16fc2844c1d9f8f815f318734554266?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nStephane Rolland<br \/>\nhaskell ghci haskell-platform<br \/>\nI&#8217;m following a tutorial. (Real World Haskell)And I have one beginner question about head and tail called on empty lists: In GHCi it returns exception.Intuitiv<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/b90b2869c203ae2a2d4615d1c7e1d1a2?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nmgibson<br \/>\nhaskell ghci type-families<br \/>\nI am wondering if there is functionality that exists within GHCi (or elsewhere) to expand type synonyms and families out of an arbitrary type expression.For example, if I have these types,data A = A data B = Bdata F a = F a data G a = G a data H a b = H a btype S a b = H (F a) (G b<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/7019dabd783b2ecfaf04f5440ebb56df?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nMike Izbicki<br \/>\nhaskell types ghci<br \/>\nI&#8217;m trying to make the types ghci displays for my libraries as intuitive as possible, but I&#8217;m running into a lot of difficulties when using more advanced type features.Let&#8217;s say I have this code in a file:{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE TypeOperators #-}import GHC.TypeLitsdata Container (xs::[*]) = ContainerI load it up in ghci, then I type the following command:ghci&gt; :t undefined ::<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/dfe88469b75efc87cbcbbbc2a975850a?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nmcandre<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/9da62513023261e37f28699b557d262a?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nTing L<br \/>\nc++ haskell inline ffi ghci<br \/>\nI have recently met an issue with C++ inline functions when using Haskell FFI to C\/C++. Namely, g++ does not really inline functions that are declared inline, and generate symbols for them. Ultimately, this generates linker error when ghci tries to load an object file which calls the inline function:Loading object (static) solveeq.o &#8230; done Loading object (dynamic) \/usr\/lib\/gcc\/x86_64-linux-gnu\/4.6\/libstdc++.so &#8230; done final link &#8230; ghc: solveeq.o: unknown symbol `_ZN5Eigen8internal19throw_std_bad_al<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/e05b3a3ecb03d2c71db5a487d8ddab1b?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nlewurm<br \/>\nhaskell ffi ghci<br \/>\nI have a problem regarding FFI in Haskell and the interactive mode of GHC.(Source is also available via a gist):FFISo.hs:{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ForeignFunctionInterface #-} module Main whereimport qualified Data.ByteString.Char8 as Bforeign import ccall &#8220;callMeFromHaskell&#8221;callMeFromHaskell :: IO ()foreign export ccall callMeFromC :: IO () callMeFromC :: IO () callMeFromC = B.putStrLn &#8220;callMeFromC&#8221;main :: IO () main = doB.putStrLn &#8220;main&#8221;callMeFromHaskellreturn ()c.c:#include void callMeFromC(void);void callMeFromHaskell(void) { printf(&#8220;callMeFromHaskell\\n&#8221;);callMeFromC(); }Makefile:GHC_OPT := -Wall -O2 -fno-warn-unused-do-bindall: ffisotest: ffiso.\/$<\/li>\n<\/ul>\n<p id=\"rop\"><small>Originally posted 2013-11-09 20:19:24. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>Matt Fenwick artella haskell ghc ghci winghci Question 1Hi, if in WinGHCi I intentionally do the following wrong piece of code : 3 4Then the error message I get is :1:1:No instance for (Num (a0 -&gt; t0))arising from the literal `3&#8217;Possible fix: add an instance declaration for (Num (a0 -&gt; t0))In the expression: 3In the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-530","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/530","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=530"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/530\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=530"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=530"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=530"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}