ghci

How to perform database queries in GHCi in Yesod Application

十年热恋 提交于 2019-12-18 16:48:15
问题 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 =

How to perform database queries in GHCi in Yesod Application

守給你的承諾、 提交于 2019-12-18 16:48:14
问题 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 =

How to provide explicit type declarations for functions when using GHCi?

倾然丶 夕夏残阳落幕 提交于 2019-12-18 10:27:35
问题 How to I define the equivalent of this function (taken from learnyouahaskell) inside GHCi? import Data.List numUniques :: (Eq a) => [a] -> Int numUniques = length . nub Without the type declaration, GHCi accepts the function definition, but it ends up with an unhelpful type: Prelude Data.List> import Data.List Prelude Data.List> let numUniques' = length . nub Prelude Data.List> :t numUniques' numUniques' :: [()] -> Int The resulting function only accepts a list of units as a parameter. Is

How to provide explicit type declarations for functions when using GHCi?

随声附和 提交于 2019-12-18 10:27:25
问题 How to I define the equivalent of this function (taken from learnyouahaskell) inside GHCi? import Data.List numUniques :: (Eq a) => [a] -> Int numUniques = length . nub Without the type declaration, GHCi accepts the function definition, but it ends up with an unhelpful type: Prelude Data.List> import Data.List Prelude Data.List> let numUniques' = length . nub Prelude Data.List> :t numUniques' numUniques' :: [()] -> Int The resulting function only accepts a list of units as a parameter. Is

How do I clear the terminal screen in Haskell?

空扰寡人 提交于 2019-12-18 10:15:01
问题 How can I clear a terminal screen after my user has selected an option from my application's menu? 回答1: :! run the shell command :! cls under windows :! clear under linux and OS X 回答2: This is what you may be looking for: ansi-terminal: Simple ANSI terminal support, with Windows compatibility You can find it in Hackage and install using cabal install ansi-terminal . It specifically has functions for clearing the screen, displaying colors, moving the cursor, etc. Using it to clear the screen

Strange Haskell expression with type Num ([Char] -> t) => t

末鹿安然 提交于 2019-12-18 07:46:40
问题 While doing some exercises in GHCi I typed and got the following> ghci> (1 "one") <interactive>:187:1: No instance for (Num ([Char] -> a0)) arising from a use of ‘it’ In a stmt of an interactive GHCi command: print it which is an error, howeve if I ask GHCi for the type of the expression it does not give any error: ghci> :type (1 "one") (1 "one") :: Num ([Char] -> t) => t What is the meaning of (1 "one") ? Why does this expression gives an error, but GHCi tells it is well typed? What is the

It works when loaded from file, but not when typed into ghci. Why?

て烟熏妆下的殇ゞ 提交于 2019-12-17 20:46:14
问题 If I put the following 2 lines into foobar.hs f 1 = 1 f x = f (x-1) then $ ghci > :load foobar.hs > f 5 1 but if I do $ ghci > let f 1 = 1 > let f x = f (x-1) > f 5 ^CInterrupted. then it does not return. Why? 回答1: The latter binding overrides the former. Use this in ghci: Prelude> :{ Prelude| let f 1 = 1 Prelude| f x = f (x-1) Prelude| :} Prelude> f 5 1 Or, without the layout: Prelude> let f 1 = 1; f x = f (x-1) Prelude> f 5 1 回答2: You have to enter it all in on one line, or using :{ and :}

Function definition by special cases in GHCi

核能气质少年 提交于 2019-12-17 07:52:13
问题 From a Haskell tutorial: We can write functions on integers by cases. -- Compute the sum of the integers from 1 to n. sumtorial :: Integer -> Integer sumtorial 0 = 0 sumtorial n = n + sumtorial (n-1) However, here's what happens when I try it: $ ghci GHCi, version 8.0.1: http://www.haskell.org/ghc/ :? for help Prelude> foo 0 = print 999 Prelude> foo n = print n Prelude> foo 0 0 What am I missing? 回答1: To use your definition in GHCi exactly as you wrote it (i.e. with multiple equations in

Show substitutions in ghci

自作多情 提交于 2019-12-13 17:16:05
问题 How can I see substitutions of variable names to their values in haskell? e.g. c2i zero ==> c2i (Chr (\x y -> y)) ==> (\x y -> y) (+ 1) 0 ==> 0 As explained in this answer. 来源: https://stackoverflow.com/questions/36650044/show-substitutions-in-ghci

Ambiguous occurrence `Just'

风格不统一 提交于 2019-12-13 14:15:42
问题 I am an absolute beginner. Going through LYAH using emacs. My current Set up: Ubuntu 12.04 LTS (Use Experience - beginner) GNU Emacs 23 (Use Experience - beginner) able to work in haskell major mode Finding difficult to follow instructions (to bring haskell libraries) at Point 2 described here. Also need guidance to enable Scion IDE. Problem: .hs code data Maybe a = Nothing | Just a While running the code, I get following error: Please ignore typo error, Originally posted: *Main> just "Haha"