haskell

How to redirect requests from domain.com to www.domain in Wai/Warp app?

徘徊边缘 提交于 2019-12-25 05:09:56
问题 My site is built in Haskell/Servant and Wai/Warp. I need to redirect all requests from my domain.com to www.domain.com with the the 301 or 302 status. I know I can do that with the help of Wai/Warp somehow. How exactly? startApp :: IO () startApp = run 1234 app 回答1: The package wai-util has a convenience function redirect' to create such a Response , so you should be able to do something like app :: Application app req respond = respond =<< redirect' status302 [] uri where Just uri = parseURI

Can't install OpenGLRaw-1.1.0.1 on OS X

给你一囗甜甜゛ 提交于 2019-12-25 05:09:26
问题 When I run $ cabal install OpenGLRaw I get the following errors. ... ... ... cbits/HsOpenGLRaw.c:78:20: error: stdlib.h: No such file or directory cbits/HsOpenGLRaw.c:79:19: error: dlfcn.h: No such file or directory cbits/HsOpenGLRaw.c: In function ‘hs_OpenGLRaw_getProcAddress’: cbits/HsOpenGLRaw.c:97:0: error: ‘NULL’ undeclared (first use in this function) cbits/HsOpenGLRaw.c:97:0: error: (Each undeclared identifier is reported only once cbits/HsOpenGLRaw.c:97:0: error: for each function it

No instance for (Show ([(String, Int)] -> Int))

烈酒焚心 提交于 2019-12-25 04:57:09
问题 to calculate the value of the expression on the fly at the production rules in happy doesn't work if I'm using the lambda expressions. For example this code Exp : let var '=' Exp in Exp { \p -> $6 (($2,$4 p):p) } | Exp1 { $1 } Exp1 : Exp1 '+' Term { \p -> $1 p + $3 p } | Exp1 '-' Term { \p -> $1 p - $3 p } | Term { $1 } Term : Term '*' Factor { \p -> $1 p * $3 p } | Term '/' Factor { \p -> $1 p `div` $3 p } | Factor { $1 } Factor : int { \p -> $1 } | var { \p -> case lookup $1 p of Nothing ->

Given a string containing numbers, What is the best way to extract these?

给你一囗甜甜゛ 提交于 2019-12-25 04:55:13
问题 I have a list of strings as follows; ["75","95 64","17 47 82"] How can I convert this to a list of Ints; [75,95,64,17,47,82] My instinct is to use map and an anonymous function? 回答1: Haskell has a few useful functions read :: String -> Int -- Restricted for clarity map :: (a -> b) -> [a] -> [b] words :: String -> [String] concatMap :: (a -> [b]) -> [a] -> [b] So you give map a function and a list and it will apply your function to each element of the list. Now knowing this, you should be able

Haskell Filter Multiples of 3 from a List to a Sublist

独自空忆成欢 提交于 2019-12-25 04:36:17
问题 I am still trying to grasp the way Haskell and Functional Programming works, and I need help understanding why my function is not working. I am trying to create a function that takes a list of integers as a parameter and filters out/returns a sublist which contains any multiples of 3 from the first list. Here is my code: module Main where sublist = [] myFunc :: [Int] -> [Int] myFunc [] = [] myFunc [t] = do if t `mod` 3 == 0 then t : sublist else myFunc [] myFunc (h:t) = do if h `mod` 3 /= 0

Primitive recursion

一个人想着一个人 提交于 2019-12-25 04:33:41
问题 Merged with How can I simplify a basic arithmetic expression?. how will i define the function 'simplify' using primitive recursion? simplify :: Expr -> Expr ... simplify Simplify an expression using basic arithmetic, e.g. simplify (Plus (Var "x") (Const 0)) = Var "x" 来源: https://stackoverflow.com/questions/324003/primitive-recursion

Haskell not in scope list comprehension

喜你入骨 提交于 2019-12-25 04:29:06
问题 all_nat x = [ls| sum ls == x] I'd like to write a function that given an integer x it returns all the lists that the result of their elements when summed is the integer x but I always get the error "not in scope: 'ls' " for both times it apperas. I'm new to haskell. What's the syntax error here? 回答1: The problem is that you need to define all used variables somewhere, but ls is undefined. Moreover, it can't be defined automatically, because the compiler doesn't know about the task — how the

Haskell - Returning the number of a-Z characters used in a string

假装没事ソ 提交于 2019-12-25 04:28:29
问题 I've been using this page on the Haskell website all day and its been really helpful with learning list functions: http://www.haskell.org/haskellwiki/How_to_work_on_lists My task at the moment is to write a single line statement that returns the number of characters (a-Z) that are used in a string. I can't seem to find any help on the above page or anywhere else on the internet I know how to count characters in a string by using length nameoflist, but I'm not sure how I would go about

Multi-line *non* match with attoparsec

北战南征 提交于 2019-12-25 04:00:41
问题 I was playing around with parsing (PostgreSQL) logs which can have entries that are multi-line. 2016-01-01 01:01:01 entry1 2016-01-01 01:01:02 entry2a entry2b 2016-01-01 01:01:03 entry3 So - with a Perl or Python script I'd just grab the next line and if it wasn't starting with a timestamp append it to the previous log entry. What is a sensible way to approach this with attoparsec hooked up to io-streams ? I clearly want to do something with lookAhead and failing to match a timestamp but my

Show function for polymorphic type

自闭症网瘾萝莉.ら 提交于 2019-12-25 03:58:12
问题 I'm trying to define the Show function for the polymorphic Tree type. Could anyone help me? import Char data Tree t = NilT | Node t (Tree t) (Tree t) class Mar t where maior :: t -> String instance Mar Tree where maior (NilT) = "a" maior (Node t a b) = "b" instance Show Tree where show = maior Thanks a Lot! Solution (given by ivanm): import Char data Tree t = NilT | Node t (Tree t) (Tree t) class Mar t where maior :: t -> String instance Mar (Tree t) where maior (NilT) = "a" maior (Node t a b