haskell

Recursive Haskell function seemingly doesn't terminate

ぐ巨炮叔叔 提交于 2020-01-02 09:11:42
问题 To improve my Haskell skills, I'm trying to solve the Advent of Code 2018. As expected, I am already stuck on day 1, specifically on part 2: --- Part Two --- You notice that the device repeats the same frequency change list over and over. To calibrate the device, you need to find the first frequency it reaches twice. For example, using the same list of changes above, the device would loop as follows: Current frequency 0, change of +1; resulting frequency 1. Current frequency 1, change of -2;

Recursive Haskell function seemingly doesn't terminate

放肆的年华 提交于 2020-01-02 09:11:02
问题 To improve my Haskell skills, I'm trying to solve the Advent of Code 2018. As expected, I am already stuck on day 1, specifically on part 2: --- Part Two --- You notice that the device repeats the same frequency change list over and over. To calibrate the device, you need to find the first frequency it reaches twice. For example, using the same list of changes above, the device would loop as follows: Current frequency 0, change of +1; resulting frequency 1. Current frequency 1, change of -2;

What type signature do I need to allow a list of functions to be converted to haskell code? [duplicate]

て烟熏妆下的殇ゞ 提交于 2020-01-02 08:49:07
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Why is such a function definition not allowed in haskell? I made a haskell function called funlist . What it does is it takes a starting value, and a list of functions, and applies all of the functions in the list to the starting value. funlist thing [function] = function thing funlist thing (function:functions) = funlist (function thing) functions funlist _ _ = error "need a list of functions" The problem with

Deserializing data form a SQL Database

一曲冷凌霜 提交于 2020-01-02 08:38:28
问题 I've a little application, backed by a database (SQLite, but it's not really relevant to the question). I've defined some types like: data Whatever = Whatever Int Int String String data ImportantStuff = ImportantStuff { id :: Int, count :: Int, name :: String, description :: String } The types are mapped to tables in the DB. When I read the data, I end up writing functions like this one: whateverFromDB :: [SqlValue] -> Whatever whateverFromDB (a:b:c:d:_) = Whatever (fromSql a) (fromSql b)

Why does `peek` with a polymorphic Ptr return GHC.Prim.Any when used with a bind?

老子叫甜甜 提交于 2020-01-02 08:38:25
问题 Using the low-level GNU Science Library bindings Bindings.Gsl.RandomNumberGeneration, I'm running into this odd type behavior in GHCi where binding changes return type from a peek into GHC.Prim.Any . I'm trying to understand why since I can't use the c'rng_alloc unless I retain the type of pointer to an rng . For eample: λ> :t c'gsl_rng_alloc c'gsl_rng_alloc :: Ptr C'gsl_rng_type -> IO (Ptr C'gsl_rng) λ> :t p'gsl_rng_mt19937 p'gsl_rng_mt19937 :: Ptr (Ptr gsl_rng_type) λ> :t peek p'gsl_rng

Converting lowercase letters to capitals

一个人想着一个人 提交于 2020-01-02 08:16:52
问题 I am a newbie in Haskell and have some problem of defining a function that would convert all small letters to capital and leave the rest intact. I tried solving this question in my book so far: capitalise :: String -> String capitalise xs = [capitalise2 ch| ch<-xs] capitalise2 :: Char -> Char capitalise2 ch | isLower ch = chr (ord ch - 32) | otherwise = ch I am getting errors: p3.hs:6:7: Not in scope: `isLower' p3.hs:6:23: Not in scope: `chr' p3.hs:6:28: Not in scope: `ord' Any help would be

Why can't cabal build mighttpd2 dynamically?

£可爱£侵袭症+ 提交于 2020-01-02 08:12:09
问题 GHC is too slow when it links my executable statically, so I want to test using "-dynamic" options. The following two commands cause the same error although cabal install mighttpd2 is ok. $cabal install --ghc-options=-dynamic mighttpd2 $cabal install --enable-executable-dynamic mighttpd2 Linking dist/build/mkindex/mkindex ... Preprocessing executable 'mightyctl' for mighttpd2-2.7.1... Process.hs:11:8: Could not find module `Data.Conduit.Process' Perhaps you haven't installed the "dyn"

Why can't cabal build mighttpd2 dynamically?

核能气质少年 提交于 2020-01-02 08:12:07
问题 GHC is too slow when it links my executable statically, so I want to test using "-dynamic" options. The following two commands cause the same error although cabal install mighttpd2 is ok. $cabal install --ghc-options=-dynamic mighttpd2 $cabal install --enable-executable-dynamic mighttpd2 Linking dist/build/mkindex/mkindex ... Preprocessing executable 'mightyctl' for mighttpd2-2.7.1... Process.hs:11:8: Could not find module `Data.Conduit.Process' Perhaps you haven't installed the "dyn"

Proof of associativity law for type-level set

不羁岁月 提交于 2020-01-02 07:55:10
问题 I'm trying to prove that type-level function Union is associative, but I'm not sure how it should be done. I proved right identity and associativity laws for type-level append function and right identity for union: data SList (i :: [k]) where SNil :: SList '[] SSucc :: SList t -> SList (h ': t) appRightId :: SList xs -> xs :~: (xs :++ '[]) appRightId SNil = Refl appRightId (SSucc xs) = case appRightId xs of Refl -> Refl appAssoc :: SList xs -> Proxy ys -> Proxy zs -> (xs :++ (ys :++ zs)) :~:

Illegal instance declaration for typeclass TF

懵懂的女人 提交于 2020-01-02 07:31:35
问题 I am having a problem declaring an instance of the following typeclass. I tried to follow the advice in the error message from the ghci compiler but still cannot get the code to compile. Any help would be appreciated. class TF p where valid :: p -> Bool lequiv :: p -> p -> Bool instance TF Bool where valid = id lequiv f g = f == g instance TF p => TF (Bool -> p) where valid f = valid (f True) && valid (f False) lequiv f g = (f True) `lequiv` (g True) && (f False) `lequiv` (g False) The error