ghci

Haskell : can only load one file at a time via :load

a 夏天 提交于 2021-02-04 13:19:04
问题 suppose I have two modules NecessaryModule1 & NecessaryModule2 (as outlined in the post Haskell : loading ALL files in current directory path. Then I have noticed in both WinGHCi and GHCi that if I do : > :load NecessaryModule1 [1 of 1] Compiling NecessaryModule1 ( NecessaryModule1.hs, interpreted ) Ok, modules loaded: NecessaryModule1. > addNumber1 2 3 5 > :load NecessaryModule2 [1 of 1] Compiling NecessaryModule2 ( NecessaryModule2.hs, interpreted ) Ok, modules loaded: NecessaryModule2. >

In GHCi, why can't I show `pure 1` in REPL?

元气小坏坏 提交于 2021-01-27 03:51:45
问题 I tried to assign a lifted value to a . λ> :m Control.Applicative λ> let a = pure 1 When I evaluated a in REPL, it prints 1 . λ> a 1 Therefore, I thought there may be an implementation of show for a , and tried this: λ> show a But the GHCi throws an error: <interactive>:70:1-4: No instance for (Show (f0 a0)) arising from a use of ‘show’ The type variables ‘f0’, ‘a0’ are ambiguous Note: there are several potential instances: instance (Integral a, Show a) => Show (GHC.Real.Ratio a) -- Defined

In GHCi, why can't I show `pure 1` in REPL?

耗尽温柔 提交于 2021-01-27 03:51:12
问题 I tried to assign a lifted value to a . λ> :m Control.Applicative λ> let a = pure 1 When I evaluated a in REPL, it prints 1 . λ> a 1 Therefore, I thought there may be an implementation of show for a , and tried this: λ> show a But the GHCi throws an error: <interactive>:70:1-4: No instance for (Show (f0 a0)) arising from a use of ‘show’ The type variables ‘f0’, ‘a0’ are ambiguous Note: there are several potential instances: instance (Integral a, Show a) => Show (GHC.Real.Ratio a) -- Defined

How can I persist the environment between GHCi reloads?

半腔热情 提交于 2021-01-27 03:48:55
问题 Basically when I :load name.hs the variables and bindings are gone. Is there some option to tell ghci keep it all? 回答1: To load a new module, you can use Prelude> :m + Mymodule But reloading and keeping interactive bindings is not generally possible. Reloading is essentially forgetting all modules and loading them again. The bindings could depend on already loaded modules. The dependency logic dictates that when GHCI forgets a module, it also needs to forget everything that depends on it,

How can I persist the environment between GHCi reloads?

久未见 提交于 2021-01-27 03:44:16
问题 Basically when I :load name.hs the variables and bindings are gone. Is there some option to tell ghci keep it all? 回答1: To load a new module, you can use Prelude> :m + Mymodule But reloading and keeping interactive bindings is not generally possible. Reloading is essentially forgetting all modules and loading them again. The bindings could depend on already loaded modules. The dependency logic dictates that when GHCI forgets a module, it also needs to forget everything that depends on it,

Is it possible to display the results of applying a Haskell type family function?

99封情书 提交于 2021-01-26 09:36:06
问题 For example, if I have these weird types: {-# LANGUAGE TypeFamilies #-} type family WeirdFamily a type instance WeirdFamily () = Int type instance WeirdFamily (a, b) = (a, WeirdFamily b) Can I display (e.g. in GHCi) the result of WeirdFamily (Bool, (Char, ())) by typing something like: :t WeirdFamily (Bool, (Char, ())) into GHCi? 回答1: Use kind! . :kind! WeirdFamily (Bool, (Char, ())) WeirdFamily (Bool, (Char, ())) :: * = (Bool, (Char, Int)) 回答2: So I have figured out an answer. Type this into

Is it possible to display the results of applying a Haskell type family function?

自闭症网瘾萝莉.ら 提交于 2021-01-26 09:35:27
问题 For example, if I have these weird types: {-# LANGUAGE TypeFamilies #-} type family WeirdFamily a type instance WeirdFamily () = Int type instance WeirdFamily (a, b) = (a, WeirdFamily b) Can I display (e.g. in GHCi) the result of WeirdFamily (Bool, (Char, ())) by typing something like: :t WeirdFamily (Bool, (Char, ())) into GHCi? 回答1: Use kind! . :kind! WeirdFamily (Bool, (Char, ())) WeirdFamily (Bool, (Char, ())) :: * = (Bool, (Char, Int)) 回答2: So I have figured out an answer. Type this into

Is it possible to display the results of applying a Haskell type family function?

泪湿孤枕 提交于 2021-01-26 09:33:22
问题 For example, if I have these weird types: {-# LANGUAGE TypeFamilies #-} type family WeirdFamily a type instance WeirdFamily () = Int type instance WeirdFamily (a, b) = (a, WeirdFamily b) Can I display (e.g. in GHCi) the result of WeirdFamily (Bool, (Char, ())) by typing something like: :t WeirdFamily (Bool, (Char, ())) into GHCi? 回答1: Use kind! . :kind! WeirdFamily (Bool, (Char, ())) WeirdFamily (Bool, (Char, ())) :: * = (Bool, (Char, Int)) 回答2: So I have figured out an answer. Type this into

Is there a way to script a ghci session?

浪子不回头ぞ 提交于 2021-01-02 08:56:36
问题 My goal is to pipe some steps for ghci to run from a bash script and then exit cleanly. The commentary online says to use runhaskell for this. This is the command I'm trying to run: ghci> import System.Random ghci> random (mkStdGen 100) :: (Int, StdGen) With expected result similar to: (-3633736515773289454,693699796 2103410263) When I drop this into a file randomtest.hs and execute it with runhaskell I get the following error:. randomtest.hs:3:1: error: Invalid type signature: random

Is there a way to script a ghci session?

筅森魡賤 提交于 2021-01-02 08:55:32
问题 My goal is to pipe some steps for ghci to run from a bash script and then exit cleanly. The commentary online says to use runhaskell for this. This is the command I'm trying to run: ghci> import System.Random ghci> random (mkStdGen 100) :: (Int, StdGen) With expected result similar to: (-3633736515773289454,693699796 2103410263) When I drop this into a file randomtest.hs and execute it with runhaskell I get the following error:. randomtest.hs:3:1: error: Invalid type signature: random