ghci

What does [safe] marker mean in ghci?

对着背影说爱祢 提交于 2019-12-01 02:29:47
问题 Prelude Data.Void> :info Void data Void -- Defined in `Data.Void' instance [safe] Eq Void -- Defined in `Data.Void' instance [safe] Ord Void -- Defined in `Data.Void' instance [safe] Read Void -- Defined in `Data.Void' instance [safe] Show Void -- Defined in `Data.Void' What does [safe] mean? 回答1: It simply means that the datatype is defined in a module which is defined using safe extension. You can find the details of the extension in the user guide. In fact, you can test that yourself by

GHCi doesn't work with FFI export declarations/shared libraries

不打扰是莪最后的温柔 提交于 2019-12-01 01:32:46
问题 I 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 where import qualified Data.ByteString.Char8 as B foreign import ccall "callMeFromHaskell" callMeFromHaskell :: IO () foreign export ccall callMeFromC :: IO () callMeFromC :: IO () callMeFromC = B.putStrLn "callMeFromC" main :: IO () main = do B.putStrLn "main" callMeFromHaskell

Why is GHCi typing this statement oddly?

别说谁变了你拦得住时间么 提交于 2019-12-01 00:17:17
问题 In answering a question on stackoverflow, I noticed that GHCi (interactive) is assigning a too-restrictive type in a let statement. Namely, given the code, import Control.Arrow f = maximum &&& id >>> fst &&& (\(m,l) -> length $ filter (==m) l) (as on my answer to https://stackoverflow.com/questions/6281813/maximum-of-list-and-count-of-repeat-maximum-number/6283594#6283594), if one inserts a "let" before f and enters this in ghci, it gives the following type information Prelude Control.Arrow>

Haskell: Function application with $

倾然丶 夕夏残阳落幕 提交于 2019-11-30 23:05:23
问题 In the following snippet, you can see my two collatz functions I wrote in Haskell. For the recursive application I used parentheses in the first example (collatz) to get the right precedence. As I have just learnt function application with $, I tried to rewrite the function (collatz') using that thing. However, I encounter the following error: Couldn't match expected type `[a]' against inferred type `a1 -> [a1]' In the second argument of `(:)', namely `collatz'' In the first argument of `($)'

No instance for (Show ([(Char, Char)] -> Char))

巧了我就是萌 提交于 2019-11-30 22:42:49
So I have to make a function that finds a pair with its 1st letter and returning the 2nd letter. I actually found one answer but with the map function and I couldn't get it. lookUp :: Char -> [(Char, Char)] -> Char lookUp x [] = x lookUp x ( ( st,nd ): rst) | st == x = nd | otherwise = lookUp x rst And I get this message: No instance for (Show ([(Char, Char)] -> Char)) arising from a use of `print' Possible fix: add an instance declaration for (Show ([(Char, Char In a stmt of an interactive GHCi command: print it Your code is fine, you just need to supply all the arguments at the ghci prompt,

Haskell Error: parse error on input `='

冷暖自知 提交于 2019-11-30 19:59:54
Specs GHC 6.12.1 Mac OS X 10.6.4 x64 MacBook Pro Problem I'm having trouble using let syntax. The following code refuses to compile: module Main where main = let x = 1 y = 2 z = 3 in putStrLn $ "X = " ++ show x ++ "\nY = " ++ show y ++ "\nZ = " ++ show z I tried tabbing in y = 2 and z = 3 even more. No dice. (Undesirable) Solutions The only way I've gotten the code to compile is either Replacing hard tabs with spaces. Replacing the let clause with a where clause. Saizan on #haskell explains that the assignments in a let expression have to align, not let itself. As long as the assignments line

Why am I able to use my value constructor even though I don't export it?

∥☆過路亽.° 提交于 2019-11-30 19:22:13
For practice, I'm implementing a queue data type in a module called "Queue". My data type is also called "Queue", as is its only value constructor: module Queue (Queue, enq, emptyQueue) where data Queue a = Queue { inbox :: [a], outbox :: [a] } deriving (Eq, Show) emptyQueue :: Queue a emptyQueue = Queue [] [] enq :: a -> Queue a -> Queue a enq x (Queue inb out) = Queue (x:inb) out -- other function definitions (irrelevant here)... As far as I understand, because I wrote Queue , not Queue(..) or Queue(Queue) in the export statement, I don't expect the value constructor of my data type to be

How to perform database queries in GHCi in Yesod Application

♀尐吖头ヾ 提交于 2019-11-30 14:12:32
How to, for example, insert a new User into a database using Yesod application's models? Or is there a better way? I am dealing with scaffolded application. Now I created App instance and dont know how to perform requests using it. :i Extra data Extra = Extra {extraCopyright :: Data.Text.Internal.Text, extraAnalytics :: Maybe Data.Text.Internal.Text} -- Defined in `Settings let e = Extra "asdf" Nothing let c = AppConfig {appEnv = Development, appPort = 3000, appRoot = "/", appHost = "localhost", appExtra = e} f <- makeFoundation c :t f f :: App :i App data App = App {settings :: AppConfig

Haskell : display/get list of all user defined functions

£可爱£侵袭症+ 提交于 2019-11-30 11:47:11
Is there a command in Haskell which displays (or get as a list of) all the user defined functions which have been loaded/defined in the GHCi? Thanks To see bindings you've made at the ghci prompt (e.g. with let or <- ), try :show bindings . If you've loaded some modules, you can use :show modules to get the names of loaded modules and then :browse ModuleName to list everything in scope from that module. When in ghci, use :browse or just :bro after loading the file. You may also browse unloaded modules via :browse Foo.Bar.Baz . 来源: https://stackoverflow.com/questions/10272094/haskell-display

Using gcc instead of clang in ghci or ghc

我与影子孤独终老i 提交于 2019-11-30 09:37:26
On Mac OSX 10.9, the default c compiler bundled with Xcode is clang . I installed gcc-4.9 with homebrew . Now I have two different gcc s, one is clang , the other is gcc . The default is clang . I want to use gcc when compiling Haskell files with ghc , and I want also gcc when I launch ghci . How to do this change? Carter Tazio Schonwald Reproducing my directions I've been sharing with haskellers for the past few months via https://gist.github.com/cartazio/7131371 Type ghc --print-libdir The output will be a path like /Library/Frameworks/GHC.framework/Versions/7.6.3-x86_64/usr/lib/ghc-7.6.3 Go