haskell

How can I have more than 9 workspaces in xmonad?

天涯浪子 提交于 2020-06-27 06:55:27
问题 I can change the names of workspaces, and presumably simply add more by changing this conststant: myWorkspaces = ["1","2","3⌂","4","5","6","7✉","8☺","9♫"] If I add something to the array, there will be more workspaces, but how do I keybind them? Mod-1 through Mod-9 are the default but I can't find documentation for how to change that default. 回答1: I found the answer buried in this example configuration and together with the key names list, it looks like the following: Defining a tenth

What is the difference between an operator and a function in Haskell?

走远了吗. 提交于 2020-06-25 18:18:42
问题 I am new to Haskell and this mixture of Infix and Prefix notation is confusing me. What is the difference between an operator like '+' and a function like head? How do I write an operator 'c' which does this 1 c 1 = 2? I found this definition a ! b = True. How does Haskell know that I am defining ! and not a function a? 回答1: In Haskell, to create an operator you must use the following "operator symbols": ! # $ % * + . / < = > ? \ ^ | : - ~ So, for example ($$$) a b = a+b Defines an operator $

How does one declare an abstract data container type in Haskell?

本秂侑毒 提交于 2020-06-25 07:54:05
问题 I read William Cook's "On Data Abstraction, Revisited", and re-read Ralf Laemmel's "The expression lemma" to try to understand how to apply the former paper's ideas in Haskell. So, I'm trying to understand how could you implement, e.g., a set union function, in Haskell without specifying the types? 回答1: There's multiple ways, depending on which version of "abstract data types" you're after. Concrete but opaque types : It's been a little while since I read Cook's lovely paper, but glancing

A concise way to factor out multiple typeclasses in Haskell?

白昼怎懂夜的黑 提交于 2020-06-25 00:58:12
问题 In my Haskell codebase, I have many functions that take polymorphic arguments. These polymorphic arguments all need to satisfy the same set of typeclasses ( RealFloat a, Floating a, Real a, Show a, Ord a, Typeable a ) and this set of typeclasses needs to be present in the functions' type annotations. Right now I've been manually writing the typeclass annotations for every function, but it gets verbose to have that list of typeclasses repeated 30+ times in my codebase, and cumbersome to have

A concise way to factor out multiple typeclasses in Haskell?

北慕城南 提交于 2020-06-25 00:54:14
问题 In my Haskell codebase, I have many functions that take polymorphic arguments. These polymorphic arguments all need to satisfy the same set of typeclasses ( RealFloat a, Floating a, Real a, Show a, Ord a, Typeable a ) and this set of typeclasses needs to be present in the functions' type annotations. Right now I've been manually writing the typeclass annotations for every function, but it gets verbose to have that list of typeclasses repeated 30+ times in my codebase, and cumbersome to have

How to functionally generate a tree breadth-first. (With Haskell)

半城伤御伤魂 提交于 2020-06-24 07:37:07
问题 Say I have the following Haskell tree type, where "State" is a simple wrapper: data Tree a = Branch (State a) [Tree a] | Leaf (State a) deriving (Eq, Show) I also have a function "expand :: Tree a -> Tree a" which takes a leaf node, and expands it into a branch, or takes a branch and returns it unaltered. This tree type represents an N-ary search-tree. Searching depth-first is a waste, as the search-space is obviously infinite, as I can easily keep on expanding the search-space with the use

How do you structure a stateful module in Haskell?

最后都变了- 提交于 2020-06-24 07:36:36
问题 I'm looking to write a generic module that allows Haskell programs to interact with Cassandra. The module will need to maintain its own state. For example, it will have a connection pool and a list of callbacks to be invoked when a new record is saved. How should I structure the code so that this module can maintain its state? Here are some of the approaches I've been considering. Am I on the right track? (I'm new to Haskell and still learning the best ways to think functionally.) Option 1:

When should one use a Kleisli?

一个人想着一个人 提交于 2020-06-24 03:24:09
问题 I recently stumbled on the concept of a Kleisli and every tutorial/link/reference that I read motivates the use of Kleisli via the following constructs: Composing functions that return monads : f: a -> m[b] with g: b -> m[c] - I think the very definition of a monad already captures this case - do/bind/for/flatMap do that. One needn't lean on the Kleisli construct to achieve this. So this cannot be the "primary" use case of a Kleisli IMO. Inserting configuration : This one states that if

When should one use a Kleisli?

瘦欲@ 提交于 2020-06-24 03:23:49
问题 I recently stumbled on the concept of a Kleisli and every tutorial/link/reference that I read motivates the use of Kleisli via the following constructs: Composing functions that return monads : f: a -> m[b] with g: b -> m[c] - I think the very definition of a monad already captures this case - do/bind/for/flatMap do that. One needn't lean on the Kleisli construct to achieve this. So this cannot be the "primary" use case of a Kleisli IMO. Inserting configuration : This one states that if

Executing a system command in Haskell

扶醉桌前 提交于 2020-06-22 13:39:32
问题 How could I execute a system command such as cp somefile somedestination in Haskell? Something like an os.Exec . 回答1: The Haskell 98 standard provides: System.system :: String -> IO GHC.IO.Exception.ExitCode which executes a command. The new System.Process library is more useful though, allowing for portable input/output redirection and so forth. 回答2: I'm not a haskell buff, but this may be what you're looking for 回答3: If you do this sort of thing a lot then it's worth having a look at http:/