Here is an example I wrote that uses if-else branches and guard expressions. When is one more appropriate over the other? The main reason I want to know this is because languages typically have a idiomatic way of doing things.
test1 a b =
if mod b 3 ≡ 0 then a + b
else if mod b 5 ≡ 0 then a + b
else a
test2 a b
| mod b...
There is an extensive collection of unique words in on the Haskell repository, cabal, (very slight exaggeration). Anyway today's term is isolate primitive. What is an isolate primitive? How does it compare to a non-isolate primitive? Unfortunately, I don't have the background to know most of the Haskell parlance, and Google isn't helping...
Could anyone please help me with my assignment questions? I've done most of it but I'm still stuck on these 3 questions.
Here is the question:
Consider the following types of search trees and balanced trees
data STree = Leaf | Node STree Int STree
data Btree = Tip Int | Branch Btree Btree
whose constructors are subject to ...
I'm currently going through the book "The Haskell Road to Logic, Math, and Programming" by Doets and Van Eijck. I've never been exposed to any functional programming language until this book, so keep that in mind.
Still early in the book, it gives the following code for a primality test:
ldp :: Integer -> Integer
ldp n = ldpf primes1 n...
Hi guys!
I'm trying to create a small module for doing decimal-based calculations. A number is stored as an integer mantisse, with a precision value specified by an int:
data APNum =
{ getMantisse :: Integer
, getPrecision :: Int }
For instance:
APNum 123 0 -> 123
APNum 123 1 -> 1.23
APNum 123 2 -> 12.3
...
(negative precision...
I've tried -fvia-C and the -pgms, but none of them manage to create an executable, splurting out lots of errors like Warning: retaining unknown function ``L4' in output from C compiler.
...
Hi guys,
Can anyone help with my last assignment question that i got stuck on for 2 days straight.
I'm suck at Haskell and this question seems to be too advanced for me, so please help me cos its due mid-night tonight.
Any help is really appreciated.
Here is my question.
Your main task in this question is to define the function
classl...
When I use GHCi, I almost always end up importing Control.Applicative, Data.List, etc. . Is there a way to configure GHCi to automatically import those modules.
Also, after importing them, how do I keep the prompt from being insanely long?
Prelude Control.Applicative Data.List Database.HDBC Database.HDBC.Sqlite3 System.Directory>
...
I'm writing my first big project in Haskell and I'd like to split it across multiple files. So far, I have written two modules, Parse and Eval. I'd like to have a Main module that just includes these two modules and specifies the main function. I have the files Main.hs, Parse.hs, and Eval.hs and import them in Main, but this happens:
Pr...
I'm writing an evaluator for a little expression language, but I'm stuck on the LetRec construct.
This is the language:
type Var = String
type Binds = [(Var, Expr)]
data Expr
= Var Var
| Lam Var Expr
| App Expr Expr
| Con Int
| Sub Expr Expr
| If Expr Expr Expr
| Let Var Expr Ex...
I'm trying to run parallel code in GHC 6.10.4 (from MacPorts) on OS X 10.5
I'm building with -threaded, in my makefile:
GHC=ghc -prof -auto-all -O -threaded
glicko: glicko.hs Lib.hs
$(GHC) --make -main-is Glicko glicko.hs lib.hs
When I invoke ./glicko +RTS -N or ./glicko +RTS -N1 the code runs, but seems to only use one CPU...
Does anybody know the steps of haskell 'foldr' use of function?
GHCI Command Window:
foldr (\x y -> 2*x + y) 4 [5,6,7]
The result after evaluation:
40
Steps on this,
Prelude> foldr (\x y -> 2*x + y) 4 [5,6,7]
6 * 2 + (7 * 2 + 4)
12 + 18 = 30
5 * 2 + 30 = 40 v
...
Is there any reason to prefer one of the following notations over the others or is this simply a matter of preference?
map toLower "FOO"
fmap toLower "FOO"
toLower <$> "FOO"
As an aside: I realize that <$> is the same as `fmap`. Am I right in the assumption that map is just a less general form of fmap?
...
Hi,
I need to use a number (a Rational ) as the log type of a Writer Monad. Unfortunately , number are not Monoid. Is there a module (or something) instantiating Numbers as Monoid, or should I do it myself ?
(I just want to know if it exists already somewhere to not reinvent the wheel, I don't need help to do it myself if needed)
...
Today I was doing the thread ring exercise from the Programming Erlang book and googled for other solutions to compare. I found that the language shootout has exactly this the same problem as a benchmark. I had the impression that this is an area where Erlang should be fastest, but turns out that C and C++ are again on top. My suspicion ...
The following line works as expected, but I am a little concerned why:
getLine >>= \x-> getLine >>= \y-> return [x, y]
Consider the addition of parenthesis to scope the lambda expressions:
getLine >>= (\x-> getLine) >>= (\y-> return [x, y])
The second line is errorneous because x is not in scope when used in the return, and I am ha...
After reading (and skimming some sections of) Wadler's paper on monads, I decided to work through the paper more closely, defining functor and applicative instances for each of the monads he describes. Using the type synonym
type M a = State -> (a, State)
type State = Int
Wadler uses to define the state monad, I have the following (us...
Does Haskell have an equivalent of Alice's ability to bind a variable to a future?
val a = spawn foo;
where foo is some function.
I know Haskell supports channels and threads; I'm hoping for syntax as natural as Alice's to bind a value to a future and spawn a thread to calculate it without having to deal with the details.
...
Hi
If you had the possibility of having an application that would use both Haskell and C++.
What layers would you let Haskell-managed and what layers would you let C++-managed ?
Has any one ever done such an association, (surely) ?
(the Haskell site tells it's really easy because Haskell has a mode where it can be compiled in C by gcc...
Whenever in Haskell we need some variant data type, we would use ADTs in conjunction with pattern matching. What do Clojure folks use for such usecases?
...