haskell

Read file with UTF-8 in Haskell as IO String

℡╲_俬逩灬. 提交于 2021-02-18 21:13:11
问题 I have the following code which works fine unless the file has utf-8 characteres : module Main where import Ref main = do text <- getLine theInput <- readFile text writeFile ("a"++text) (unlist . proc . lines $ theInput) With utf-8 characteres I get this: hGetContents: invalid argument (invalid byte sequence) Since the file I'm working with has UTF-8 characters, I would like to handle this exception in order to reuse the functions imported from Ref if possible. Is there a way to read a UTF-8

ghc can't find my cabal installed packages

冷暖自知 提交于 2021-02-18 21:12:57
问题 I've installed ghc 6.12.3, and then the Haskell Platform. I'm trying to compile a test program: $ ghc test.hs test.hs:3:0: Failed to load interface for `Bindings': Use -v to see a list of the files searched for. so, naturally, I do cabal install Bindings Which works fine, and places the package in ~/.cabal/lib/bindings-0.1.2 The problem is, that when I go to compile again with ghc, it still doesn't find the package I've installed with cabal. compiling in verbose mode gives: ghc -v test.hs

ghc can't find my cabal installed packages

廉价感情. 提交于 2021-02-18 21:12:53
问题 I've installed ghc 6.12.3, and then the Haskell Platform. I'm trying to compile a test program: $ ghc test.hs test.hs:3:0: Failed to load interface for `Bindings': Use -v to see a list of the files searched for. so, naturally, I do cabal install Bindings Which works fine, and places the package in ~/.cabal/lib/bindings-0.1.2 The problem is, that when I go to compile again with ghc, it still doesn't find the package I've installed with cabal. compiling in verbose mode gives: ghc -v test.hs

How to use type-level functions to create static types, dynamically?

做~自己de王妃 提交于 2021-02-18 17:39:14
问题 In TypeScript, there are type-level functions that allow creating new types based on given literal types/specifications (see Mapped Types, Conditional Types, etc.). For instance, here is such a function , let say provided by a lib author: type FromSpec<S> = { [K in keyof S]: S[K] extends "foo" ? ExampleType : never }; Its purpose is, given a specification S in the form of a map of string keys and arbitrary literals, it creates a new type in the form of a map with the same set of keys and with

Lookup query parameters in Yesod

和自甴很熟 提交于 2021-02-18 10:56:52
问题 I just initialized a Yesod project (no database) using yesod init . My HomeR GET handler looks like this: getHomeR :: Handler Html getHomeR = do (formWidget, formEnctype) <- generateFormPost sampleForm let submission = Nothing :: Maybe (FileInfo, Text) handlerName = "getHomeR" :: Text defaultLayout $ do aDomId <- newIdent setTitle "Welcome To Yesod!" $(widgetFile "homepage") When using yesod devel , I can access the default homepage at http://localhost:3000/ . How can I modify the handler

What is the assumption made in “Learn You a Haskell” when deducing the kind?

一笑奈何 提交于 2021-02-18 09:05:21
问题 This question is not subjective. A very specific verb is used in the referenced book, and I'd like to understand what the implication of that phrasing is, because I'm afraid I'm misunderstanding something. From Learn You a Haskell, the following paragraph is the third and last one containing "we assume * ". data Barry t k p = Barry { yabba :: p, dabba :: t k } And now we want to make it an instance of Functor . Functor wants types of kind * -> * but Barry doesn't look like it has that kind.

Extending propositional logic to modal logic in Haskell

有些话、适合烂在心里 提交于 2021-02-18 06:32:49
问题 I have written some code in Haskell for modeling propositional logic data Formula = Prop {propName :: String} | Neg Formula | Conj Formula Formula | Disj Formula Formula | Impl Formula Formula | BiImpl Formula Formula deriving (Eq,Ord) However, there is no natural way to extend this to Modal Logic, since the data type is closed. Therefore, I thought I should use classes instead. That way, I can easily add new language features in different modules later on. The problem is that I don't exactly

How do I get text-icu working on Windows?

一个人想着一个人 提交于 2021-02-17 18:00:18
问题 I was able to cabal install text-icu without errors. (I used --extra-lib-dirs and --extra-include-dirs to point to the lib and include directories in the binary distribution of icu4c.) I was also able to build the following simple program that uses text-icu , by doing ghc --make icu.hs : -- icu.hs import Data.Text.ICU main = print $ Locale "tr-TR" No errors or warnings in either of these steps. But when I try to run the compiled program, icu.exe , I get no output at all. I expected to get a

How do I get text-icu working on Windows?

余生颓废 提交于 2021-02-17 17:59:50
问题 I was able to cabal install text-icu without errors. (I used --extra-lib-dirs and --extra-include-dirs to point to the lib and include directories in the binary distribution of icu4c.) I was also able to build the following simple program that uses text-icu , by doing ghc --make icu.hs : -- icu.hs import Data.Text.ICU main = print $ Locale "tr-TR" No errors or warnings in either of these steps. But when I try to run the compiled program, icu.exe , I get no output at all. I expected to get a

How do I get text-icu working on Windows?

只愿长相守 提交于 2021-02-17 17:59:31
问题 I was able to cabal install text-icu without errors. (I used --extra-lib-dirs and --extra-include-dirs to point to the lib and include directories in the binary distribution of icu4c.) I was also able to build the following simple program that uses text-icu , by doing ghc --make icu.hs : -- icu.hs import Data.Text.ICU main = print $ Locale "tr-TR" No errors or warnings in either of these steps. But when I try to run the compiled program, icu.exe , I get no output at all. I expected to get a