haskell

Extending the list of static autocompletion commands with dynamic values

∥☆過路亽.° 提交于 2019-12-24 15:29:27
问题 I have following program in Haskell that takes input from command line and modifies state of mydata variable: {-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, UndecidableInstances #-} import Text.Regex.PCRE import System.Console.Haskeline import System.IO import System.IO.Unsafe import Control.Monad.State.Strict import qualified Data.ByteString.Char8 as B import Data.Maybe import Data.List import qualified Data.Map as M data MyDataState = MyDataState { mydata :: [Int], showEven :: Bool

How to write a minimal-overhead proxy to localhost:3389 in Haskell?

Deadly 提交于 2019-12-24 15:27:49
问题 Update: question now contains the final edited answer! I now use the following (final answer): module Main where import Control.Concurrent (forkIO) import Control.Monad (when,forever,void) import Network (PortID(PortNumber),listenOn) import Network.Socket hiding (listen,recv,send) import Network.Socket.ByteString (recv,sendAll) import qualified Data.ByteString as B import System type Host = String type Port = PortNumber main :: IO () main = do [lp,h,p] <- getArgs start (port lp) h (port p)

Could someone explain gtk2hs drag and drop to me, the listDND.hs demo just isn't doing it for me?

旧巷老猫 提交于 2019-12-24 15:19:29
问题 As the title says, I just don't get DND (or rather I understand the concept and I understand the order of callbacks, I just don't understand how to setup DND for actual usage.) I'd like to say that I've done DND stuff before in C, but considering I never really got that working... So I'm trying (and mostly succeeding, save DND) to write a text editor (using gtksourceview, because it has built in code highlighting.) Reasons are below if you want them. Anyways, there's not really a good DND

Is the gdiff library obsolete?

一笑奈何 提交于 2019-12-24 15:06:05
问题 I just had a closer look at the gdiff library and wondered if some of the work there could be shifted into GHC Generics and/or Typeables. To make this a solid question: could the library be improved and deflated by utilizing features available in current ghc versions? 来源: https://stackoverflow.com/questions/28707547/is-the-gdiff-library-obsolete

Haskell counting number of function call

倾然丶 夕夏残阳落幕 提交于 2019-12-24 14:37:06
问题 Say I have a function concat :: String -> String -> String . So, var :: String var = concat (concat "a" "b") "c") -- "abc" Now, I have a function which I want to use to calculate how many times concat is called: func :: (String->String->String) -> Int So, func var should return 2. How should I get this value and at the same time perform the concat? 回答1: Putting aside that var has the wrong type, you can't. Reason 1: You can write exactly the same function as var without ever calling concat .

Modifying Emacs Inferior Haskell processes to enable CPP processing

ⅰ亾dé卋堺 提交于 2019-12-24 14:23:58
问题 If we look at the source of The random package we have a file Random.hs . Because of CPP extensions one has to invoke ghci via the following command : ghci -cpp Random.hs Alternatively one can do : ghci -cpp and then from within ghci : Prelude GOA> :load Random [1 of 1] Compiling System.Random ( Random.hs, interpreted ) Ok, modules loaded: System.Random. If I use Emacs Inferior Haskell mode (Emacs/Inferior Haskell processes) and I have the source : module Main where import System.Random gen =

How to conciliate / constraint types between two separated expressions

耗尽温柔 提交于 2019-12-24 13:38:35
问题 I'm playing with haskell-distributed (Cloud Haskell) and I cannot make use of type constraint using returning type (must be as ... -> Process () ). To simplify context (and give a reproducible example), let -- Request / Response data ReqRes a b = Req a | Res b deriving (Read, Show) and one generic function mapping generic processes compute :: (Read a, Read b, Show a, Show b) => (a -> b) -> IO () compute f = do req <- readLn case req of Res _ -> error "Req expected" Req a -> print $ Res $ f a

Functionality of adding to lists in Haskell / overwriting an existing List

二次信任 提交于 2019-12-24 13:13:10
问题 type Dictionary = [(String, String)] dict :: Dictionary dict = ("Deutsch", "English"):[] insert :: Dictionary -> (String,String) -> Dictionary insert dict entry = dict ++ [entry] One thing that I didn't find about the way lists work: Is it somehow possible to overwrite the existing dict with the entry added in insert? Or is it necessary to, in the next step, always write out the list that was put out by insert? insert [("German", "English"), ("Hallo", "hello")] ("Versuch", "try") So far, this

Film database in Haskell

情到浓时终转凉″ 提交于 2019-12-24 12:59:30
问题 Currently trying to solve 2 main questions in my haskell program. display all films that a given user is a fan of display all the films of a given actor that were released during a particular period (i.e. between a given start year and end year) This is the sample database I am currently using: type Title = String type Cast = String type Year = Int type Fans = String type Film = (Title, [Cast], Year, [Fans]) type Database = [Film] testDatabase :: Database testDatabase = [("Casino Royale", [

How does `lens` work?

旧时模样 提交于 2019-12-24 12:51:55
问题 I mean, not the simple stuff like this (from here): strike :: StateT Game IO () strike = do lift $ putStrLn "*shink*" boss.health -= 10 But things like using lens to map over types from Linear . How would I express this in terms of lens: vecMod :: (Integral a) => V2 a -> V2 a -> V2 a vecMod (V2 x1 y1) (V2 x2 y2) = V2 (x1 `mod` x2) (y1 `mod` y2) Another example: my current code is full of small expressions like this: isAt :: Thing -> Position -> Game Bool isAt thing pos = do b <- use board