Search Results

Search found 762 results on 31 pages for 'haskell'.

Page 17/31 | < Previous Page | 13 14 15 16 17 18 19 20 21 22 23 24  | Next Page >

  • What do you do when you feel you need a variadic list comprehension?

    - by cspyr0
    I would like to make a method where I could give it a list of lengths and it would return all combinations of cartesian coordinates up to those lengths. Easier to explain with an example: cart [2,5] Prelude> [ [0,0],[0,1],[0,2],[0,3],[0,4],[1,0],[1,1],[1,2],[1,3],[1,4] ] cart [2,2,2] Prelude> [ [0,0,0],[0,0,1],[0,1,0],[0,1,1],[1,0,0],[1,0,1],[1,1,0],[1,1,1] ] A simple list comprehension won't work because I don't know how long the lists are going to be. While I love Haskell's simplicity for many problems, this is one that I could write procedurally (in C or something) in 5 minutes whereas Haskell gives me an aneurysm! A solution to this specific problem would help me out a lot; I'd also love to hear about your thought processes when tackling stuff like this.

    Read the article

  • printing menu in terminal and choosing an option, how to?

    - by carlos
    I'm a haskell beginner. I'm trying to make a program that shows a menu through terminal and ask user to introduce an option. Here is the code: main :: IO () main = do putStrLn "0 <- quit" putStrLn "1 <- Hello" putStr "Choose an option: " c <- getChar case c of '0' -> return () '1' -> putChar '\n' >> putStrLn "Hello World" >> main When I use this module in the ghci interpreter everything works like it's suposed to do. But if i compile this with: ghc hello.hs and run it in the terminal, it doesn't display the line "Choose an option:" before ask for a char to be introduced. I think this may be caused because of haskell lazy nature and I don't know how to fix it. Any ideas?

    Read the article

  • Does any method exist quickly to detect valid range versions of used library

    - by daneel-yaitskov
    I'm a beginner Haskell programmer. I have written some useful code for the last six month. And I want to release a library from it. The code will use system installation cabal as any Haskell library. A library is released with cabal has a meta data file where there is a logical predicate from the libraries and their versions. A developer usually uses one set libraries. It tediously care a set of the sets libraries. How to know either my library is compiled successfully or not for some subset libraries?

    Read the article

  • How to protect against GHC7 compiled programs taking all memory?

    - by Petr Pudlák
    When playing with various algorithms in Haskell it often happens to me that I create a program with a memory leak, as it often happens with lazy evaluation. The program taking all the memory isn't really fun, I often have difficulty killing it if I realize it too late. When using GHC6 I simply had export GHCRTS='-M384m' in my .bashrc. But in GHC7 they added a security measure that unless a program is compiled with -rtsopts, it simply fails when it is given any RTS option either on a command line argument or in GHCRTS. Unfortunately, almost no Haskell programs are compiled with this flag, so setting this variable makes everything to fail (as I discovered in After upgrading to GHC7, all programs suddenly fail saying "Most RTS options are disabled. Link with -rtsopts to enable them."). Any ideas how to make any use of GHCRTS with GHC7, or another convenient way how to prevent my programs taking all memory?

    Read the article

  • Why I am forced to write the (Data Constructor) name with first letter in small case?

    - by Optimight
    Why I am forced to write "liOfLi" in place of "LiOfLi"? Please guide. code in baby.hs LiOfLi = [ [1,3,4,5,6,8], [ 12, 13, 15, 16, 19, 20], [23, 24, 25, 45, 56] ] ghci response: ghci :l baby [1 of 1] Compiling Main ( baby.hs, interpreted ) Failed, modules loaded: none. ghci baby.hs:29:1: Not in scope: data constructor `LiOfLi' When changing the initial letter to smaller case code in baby.hs liOfLi = [ [1,3,4,5,6,8], [ 12, 13, 15, 16, 19, 20], [23, 24, 25, 45, 56] ] ghci response: ghci :l baby [1 of 1] Compiling Main ( baby.hs, interpreted ) Ok, modules loaded: Main. Following are the SO questions I refered but I failed to understand the rules/ logic and get the answer for (my) abovementioned question. Why does Haskell force data constructor's first letter to be upper case? the variable names need to be lowercase. The official documentation related to this is at haskell.org/onlinereport/intro.html#namespaces – (the SO comment by) Chris Kuklewicz

    Read the article

  • What is a good method to solve cabal install problems?

    - by sp3ctum
    I've used the cabal package manager for Haskell programs to install libraries and new projects that I've cloned from some repositories. More often than not, I keep running into problems. Most projects make installing them seem super easy, but in my case that's not always true - sometimes they are very hard to get running. Some are so hard, in fact, that I've lost interest in the project solely because of not being able to install it. So instead of complaining, I'd like to ask what I should do to better this situation. I'd like to use my most recent problem as an example. I'm interested in trying out the Gitit project. It's a promising looking personal wiki that runs on various version control systems. So here's what I've done: Clone from Github run cabal install in the project directory like I'm told on the project install page: mika@eka:~/git/gitit$ ls BLUETRIP-LICENSE CHANGES HCAR-gitit.tex LICENSE Network README.markdown RELANN-0.6.1 Setup.lhs TANGOICONS YUI-LICENSE data expireGititCache.hs gitit.cabal gitit.hs plugins mika@eka:~/git/gitit$ cabal install Resolving dependencies... cabal: cannot configure happstack-server-7.0.7. It requires base64-bytestring ==1.0.* For the dependency on base64-bytestring ==1.0.* there are these packages: base64-bytestring-1.0.0.0. However none of them are available. base64-bytestring-1.0.0.0 was excluded because gitit-0.10 requires base64-bytestring ==0.1.* mika@eka:~/git/gitit$ So now I'm thinking: well, I'll install happstack-server on its own, maybe that will work: mika@eka:~/git/gitit$ cabal install happstack-server Resolving dependencies... Warning: happstack-server.cabal: Ignoring unknown section type: test-suite Configuring happstack-server-7.0.7... cabal: At least the following dependencies are missing: blaze-html ==0.5.*, hslogger >=1.0.2, monad-control ==0.3.*, network >=2.2.3, sendfile >=0.7.1 && <0.8, system-filepath >=0.3.1, text >=0.10 && <0.12, threads >=0.5, transformers-base ==0.4.* cabal: Error: some packages failed to install: happstack-server-7.0.7 failed during the configure step. The exception was: ExitFailure 1 So looks like there are some dependencies missing. But isn't installing these dependencies the whole point of using cabal in the first place? What should I do? File bug reports (to which project?), install the dependencies manually or something else? Bonus points for explaining what causes these kinds of problems.

    Read the article

  • ADT-like polymorphism in Java (without altering class)

    - by ffriend
    In Haskell I can define following data type: data Tree = Empty | Leaf Int | Node Tree Tree and then write polymorphic function like this: depth :: Tree -> Int depth Empty = 0 depth (Leaf n) = 1 depth (Node l r) = 1 + max (depth l) (depth r) In Java I can emulate algebraic data types with interfaces: interface Tree {} class Empty implements Tree {} class Leaf implements Tree { int n; } class Node implements Tree { Tree l; Tree r; } But if I try to use Haskell-like polymorphism, I get an error: int depth(Empty node) { return 0; } int depth(Leaf node) { return 1; } int depth(Node node) { return 1 + Math.max(depth(node.l), depth(node.r)); // ERROR: Cannot resolve method 'depth(Tree)' } Correct way to overcome this is to put method depth() to each class. But what if I don't want to put it there? For example, method depth() may be not directly related to Tree and adding it to class would break business logic. Or, even worse, Tree may be written in 3rd party library that I don't have access to. In this case, what is the simplest way to implement ADT-like polymorpism? Just in case, for the moment I'm using following syntax, which is obviously ill-favored: int depth(Tree tree) { if (tree instanceof Empty) depth((Empty)tree) if (tree instanceof Leaf) depth((Leaf)tree); if (tree instanceof Node) depth((Node)tree); else throw new RuntimeException("Don't know how to find depth of " + tree.getClass()); }

    Read the article

  • Non-Mainstream Languages, Bad for your resume?

    - by Joe
    Hi folks, I got my BS in Computer Science about seven years ago. I spent two years in neuroscience research and the next three providing what amounts to tech support. But I love computer programming - and I have since written, as a freelancer, non-trivial commercial code in Haskell, Smalltalk, and Objective-C. I used these languages because I find them rewarding, they make me a better programmer and thus, I thought, more attractive to companies. However the polar opposite has occured and I am now unhireable. The freelance market has bottomed out and I am looking for regular employment. But I am being repeatedly turned down, even for entry-level positions, because I don't specifically fit the requirements - eg. Java programmer with 2+ years with JUnit, JavaMail, Servlets etc. And none of the hiring managers, let alone the recruiters, have heard of either Haskell or Smalltalk and more disturbing is their thinly veiled contempt for my background. My question is , how should I market myself to these positions? Is anyone here in a similar position? What should I be doing different professionally? More broadly is this contempt for non-mainstream experience occurring everywhere or just my town? And if there are any hiring managers reading this, I'd love to hear your side. Please be brutally honest. thanks, joe

    Read the article

  • Is functional GUI programming possible?

    - by eman
    I've recently caught the FP bug (trying to learn Haskell), and I've been really impressed with what I've seen so far (first-class functions, lazy evaluation, and all the other goodies). I'm no expert yet, but I've already begun to find it easier to reason "functionally" than imperatively for basic algorithms (and I'm having trouble going back where I have to). The one area where current FP seems to fall flat, however, is GUI programming. The Haskell approach seems to be to just wrap imperative GUI toolkits (such as GTK+ or wxWidgets) and to use "do" blocks to simulate an imperative style. I haven't used F#, but my understanding is that it does something similar using OOP with .NET classes. Obviously, there's a good reason for this--current GUI programming is all about IO and side effects, so purely functional programming isn't possible with most current frameworks. My question is, is it possible to have a functional approach to GUI programming? I'm having trouble imagining what this would look like in practice. Does anyone know of any frameworks, experimental or otherwise, that try this sort of thing (or even any frameworks that are designed from the ground up for a functional language)? Or is the solution to just use a hybrid approach, with OOP for the GUI parts and FP for the logic? (I'm just asking out of curiosity--I'd love to think that FP is "the future," but GUI programming seems like a pretty large hole to fill.)

    Read the article

  • How can I implement a splay tree that performs the zig operation last, not first?

    - by Jakob
    For my Algorithms & Data Structures class, I've been tasked with implementing a splay tree in Haskell. My algorithm for the splay operation is as follows: If the node to be splayed is the root, the unaltered tree is returned. If the node to be splayed is one level from the root, a zig operation is performed and the resulting tree is returned. If the node to be splayed is two or more levels from the root, a zig-zig or zig-zag operation is performed on the result of splaying the subtree starting at that node, and the resulting tree is returned. This is valid according to my teacher. However, the Wikipedia description of a splay tree says the zig step "will be done only as the last step in a splay operation" whereas in my algorithm it is the first step in a splay operation. I want to implement a splay tree that performs the zig operation last instead of first, but I'm not sure how it would best be done. It seems to me that such an algorithm would become more complex, seeing as how one needs to find the node to be splayed before it can be determined whether a zig operation should be performed or not. How can I implement this in Haskell (or some other functional language)?

    Read the article

  • Enable --hyperlink-source for "cabal install"

    - by Tener
    The command cabal haddock has very useful --hyperlink-source option. I would like to have the source hyperlinked when building documentation with cabal install. The ticket #517 seems to be just about it: http://hackage.haskell.org/trac/hackage/ticket/517 However, perhaps it is possible to set this flag via ~/.cabal/config file? If not, how can I get working cabal-install build with the patch from #517 without installing Cabal-0.9, which is currently mandatory (due to one patch from December)?

    Read the article

  • Enable --hyperling-source for "cabal install"

    - by user263407
    The command cabal haddock has very useful --hyperlink-source option. I would like to have the source hyperlinked when building documentation with cabal install. The ticket #517 seems to be just about it: http://hackage.haskell.org/trac/hackage/ticket/517 However, perhaps it is possible to set this flag via ~/.cabal/config file? If not, how can I get working cabal-install build with the patch from #517 without installing Cabal-0.9, which is currently mandatory (due to one patch from December)?

    Read the article

  • GHCi error: Not in scope

    - by dmindreader
    I'm trying to compile this function from Learn You a Haskell for Great Good. removeNonUppercase st = [ c | c <- st, c `elem` ['A'..'Z']] by placing it into a removeNonUpperCase.hs file. It compiles fine, but when passing the argument: ghci> removeNonUppercase "Hahaha! Ahahaha!" the compiler says: <interactive>:1:0: Not in scope: 'removeNonUpperCase' Why?

    Read the article

  • ghc-pkg vs cabal

    - by Ben Lever
    In relation to how packages are created, installed and used in Haskell, what are the differences between ghc-pkg and cabal? When would you use one or the other or both? Are they complementary tools, competitive tools, or simply tools that do different jobs?

    Read the article

  • Why must recursion be in a separate file in hugs?

    - by Casebash
    In Haskell in 5 steps the factorial function is defined as follows: let fac n = if n == 0 then 1 else n * fac (n-1) But for hugs, it says that fac needs to be in fac.h. Can anyone explain why this is the case - missing the ability to define recursion seems like a massive limitation for an interpreter.

    Read the article

  • Generics and Constrained Polymorphism versus Subtyping

    - by Rahul G
    Hullo all. In this (Warning: PDF) presentation on Haskell Type Classes, on slide #54, there's this question: Open Question: In a language with generics and constrained polymorphism, do you need subtyping too? My questions are: How do generics and constrained polymorphism make subtyping unnecessary? If generics and constrained polymorphism make subtyping unnecessary, why does Scala have subtyping?

    Read the article

  • List of GHC extensions

    - by yairchu
    I wanted to use {-# LANGUAGE OverloadedStrings #-} but I forgot how it's called. This kind of thing isn't hoogle-able, and also it takes some time finding using google*. Is there somewhere a list of GHC extensions named as they are in the LANGUAGE pragma? * My googling search journey: Google Haskell at wikipedia GHC at wikipedia GHC language features Overload string literals OverloadedStrings

    Read the article

  • run wxHaskell on other machine

    - by snorlaks
    Hello, I've compiled haskell program which uses wxHaskell library, now I would like to know how to make it run on other machines which doesn't have wxHaskell installed. Of course I can see errors and I can copy dlls written in output and copy them to that machine but what is professioal sollution, can I write any installer or something like that? thanks for help

    Read the article

  • How can my-program.hs get its version number from my-program.cabal at build time?

    - by Dave Hinton
    I would like my cabalised program to have a --version switch. I would like it to report the same version as is present in the .cabal file. If I have to update the version number separately in my Haskell source code as well as in the .cabal file, I will eventually get them out of sync. So, how can my program, while being compiled under cabal, get its version number from the .cabal file?

    Read the article

< Previous Page | 13 14 15 16 17 18 19 20 21 22 23 24  | Next Page >