Search Results

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

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

  • Higher-kinded Types with C++

    - by Venkat Shiva
    This question is for the people who know both Haskell (or any other functional language that supports Higher-kinded Types) and C++... Is it possible to model higher kinded types using C++ templates? If yes, then how?

    Read the article

  • How can I compile a GUI executable with ghc?

    - by martingw
    I ported a little Haskell program I wrote from Mac to Windows. It's a GUI application (wxHaskell, compiled with ghc 6.12.1), so it does not need the command prompt window to open. It does so, anyway, so my question: What must I do so that the program starts without opening a prompt window first? Is there some ghc switch for this?

    Read the article

  • Emacs align-regexp on = but not ==

    - by Karl
    I am working in Haskell and frequently come across code similar to the following: func i j | i == j = i | otherwise = j I want to align on the '=' character using align-regexp but don't have the elisp knowhow. I have tried just doing " = " without the quotes, but this inserts an unwanted space character before each '='. I have found a proposed solution here but I can't seem to get that to do anything at all. Please help me write a function or hard-coded macro that will allow me to set a keybinding for this.

    Read the article

  • Scala Hoogle equivalent?

    - by Alexey Romanov
    Hoogle allows you to search many standard Haskell libraries by either function name, or by approximate type signature. I find it very useful. Is there anything like Hoogle for Scala? Search in ScalaDoc 2 only finds types and packages by name.

    Read the article

  • Is there a suitable replacement for C++, when I would like to write video processing applications?

    - by Nisanio
    Hi I want to write a video editing software, and the "logical" conclusion is that the language I must to use is C++... But I don't like it (sorry c++ fans) I would like to write it with something cool, like Lisp or Haskell or Erlang... But I don't know if the open source implementation of those languages (I don't have money to buy licenses) let me made a competitive software (in the performance area) What do you think? what do you recommend?

    Read the article

  • Outputing UTF-8 string on Mac OS's Terminal

    - by SuperBloup
    I got a programm in haskell outputting utf-8 using the package utf8-string and using only the output functions of this package. I set the encoding of each file I write to this way : hSetEncoding myFile utf8 {- myFile may be stdout -} but when I try to output : alpha = [fromEnum 0x03B1] {- a -} instead of the nice alpha letter I got on Linux (or in a file on windows), I got the following : α The weird thing is even if I try to write the output on a file, I can't read it back with mvim as an utf-8 file. Is there any way to get the correct behaviour

    Read the article

  • How to install new modes in emacs 23 on OS X?

    - by estanford
    I just downloaded the Haskell and J modes off of SourceForge, and I'm having trouble figuring out how to make them interface with emacs 23. Google searches yield detailed instructions for emacs 22, but it looks like changes have been made that make it hard to figure out where I'm supposed to stick the binaries. The internal documentation seems to assume more experience with emacs internals than I currently have, and the problem has resisted solution for several days. Does anyone know how to get these modes up and running?

    Read the article

  • Where are the clever uses of strict evaluation?

    - by devonrt
    It seems like there are plenty of examples of clever things being done in a lazily-evaluated language that can't be done in an environment with strict evaluation. For example infinite lists in Haskell or replacing every element in a tree with the tree's minimum value in one pass. Are there any examples of clever things being done in a strictly-evaluated language that can't easily be done in a lazily-evaluated language?

    Read the article

  • What is wrong with this list comprehension code?

    - by suresh
    My aim is to list all elements of the array a whose values are greater than their index positions. I wrote a Haskell code like this. [a|i<-[0..2],a<-[1..3],a!!i>i] When tested on ghci prelude prompt, I get the following error message which I am unable to understand. No instance for (Num [a]) arising from the literal 3 at <interactive>:1:20 Possible fix: add an instance declaration for (Num [a])

    Read the article

  • Newbie: understanding main and IO()

    - by user1640285
    While learning Haskell I am wondering when an IO action will be performed. In several places I found descriptions like this: "What’s special about I/O actions is that if they fall into the main function, they are performed." But in the following example, 'greet' never returns and therefore nothing should be printed. import Control.Monad main = greet greet = forever $ putStrLn "Hello World!" Or maybe I should ask: what does it mean to "fall into the main function"?

    Read the article

  • How to define a function in ghci across multiple lines

    - by Peter McGrattan
    I'm trying to define any simple function that spans multiple lines in ghci, take the following as an example: let abs n | n >= 0 = n | otherwise = -n So far I've tried pressing Enter after the first line: Prelude> let abs n | n >= 0 = n Prelude> | otherwise = -n <interactive>:1:0: parse error on input `|' I've also attempted to use the :{ and :} commands but I don't get far: Prelude> :{ unknown command ':{' use :? for help. I'm using GHC Interactive version 6.6 for Haskell 98 on Linux, what am I missing?

    Read the article

  • How to view output .mp files from Functional MetaPost

    - by Jared Updike
    I'm interested in using Functional MetaPost on Mac OS X: http://cryp.to/funcmp/ I'm looking for a tutorial like: http://haskell.org/haskellwiki/Haskell_in_5_steps but for a trivial FuncMP example, i.e. using GHC, I can compile something simple such as: import FMP myPicture = text "blah" main = generate "foo" 1 myPicture but I can't figure out how to view this foo.1.mp output. (It gives a runtime error about not finding 'virmp'; my MetaPost binary is 'mpost'; I can't figure out how to override this Parameter or what my .FunMP file is or should be doing...) I can run mpost on that but the output (foo.1.1) is what, PostScript? EPS? How do I use this? (I imagine I just need a simple LaTeX file with an EPS figure in it or something...) Preferably, I'd like to generate output (.ps or .pdf that I can view) so I an actually get somewhere with Functional MetaPost, learning it, playing with it, not banging my head against paths and binaries and shell commands.

    Read the article

  • reinventing the wheels: Node.JS/Event-driven programming v.s. Functional Programming?

    - by ivanTheTerrible
    Now there's all the hype lately about Node.JS, an event driven framework using Javascript callbacks. To my limited understanding, its primary advantage seems to be that you don't have to wait step by step sequentially (for example, you can fetch the SQL results, while calling other functions too). So my question is: how is this different, or better than just functional languages, like CL, Haskell, Clojure etc? If not better, then why don't people just do functional languages then (instead of reinventing the wheel with Javascript)? Please note that I have none experience in either Node.JS nor functional programming. So some basic explanation can be helpful.

    Read the article

  • C compiler selection in cabal package

    - by ony
    Today I've tried C compiler (Clang) for C code I use in my haskell library and found that I can gain speed increase in comparsing with my system compiler (GCC 4.4.3) from 426.404 Gbit/s to 0.823 Tbit/s So I decided to add some flags to control the way that C source file is compiled (i.e. something like use-clang, use-intel etc.). Snippet of cabal package description file: C-Sources: c_lib/tiger.c Include-Dirs: c_lib Install-Includes: tiger.h if flag(debug) GHC-Options: -debug -Wall -fno-warn-orphans CPP-Options: -DDEBUG CC-Options: -DDEBUG -g else GHC-Options: -Wall -fno-warn-orphans Question is: which options in descritpion file need to be modified to change C compiler used to compile "c_lib/tiger.c"? I did found only CC-Options.

    Read the article

  • newbie question -- how does one override show for a newtype?

    - by gatoatigrado
    I want to override the default integer constructors in Haskell so they produce strings (mostly for curiosity, but temporarily to make a nice input alternative for LaTeX's \frac{}{} inconvenience). I wanted to be able to use the language itself, instead of a special parser, but I guess that's probably not going to work out... module Main where import Prelude hiding ((+)) newtype A = A Int deriving (Eq, Show, Num) default (A) (+) :: A -> (A -> String) (A a) + (A b) = (show a) ++ " + " ++ (show b) main2 = 3+4 main :: IO () main = putStrLn main2 The problem with the above is that the + function only works for (A, A) instead of (A, String), etc. If one simply leaves out the pattern match "(A a)" and writes "a" instead, then the show() function prepends "A " so "3" becomes "A 3" instead of just "3". I want to override Show for A, but it seems to be quite a headache...

    Read the article

  • A way to measure performance

    - by Andrei Ciobanu
    Given Exercise 14 from 99 Haskell Problems: (*) Duplicate the elements of a list. Eg.: *Main> dupli''' [1..10] [1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10] I've implemented 4 solutions: {-- my first attempt --} dupli :: [a] -> [a] dupli [] = [] dupli (x:xs) = replicate 2 x ++ dupli xs {-- using concatMap and replicate --} dupli' :: [a] -> [a] dupli' xs = concatMap (replicate 2) xs {-- usign foldl --} dupli'' :: [a] -> [a] dupli'' xs = foldl (\acc x -> acc ++ [x,x]) [] xs {-- using foldl 2 --} dupli''' :: [a] -> [a] dupli''' xs = reverse $ foldl (\acc x -> x:x:acc) [] xs Still, I don't know how to really measure performance . So what's the recommended function (from the above list) in terms of performance . Any suggestions ?

    Read the article

  • How do functional programming languages work?

    - by eSKay
    I was just reading this excellent post, and got some better understanding of what exactly object oriented programming is, how Java implements it in one extreme manner, and how functional programming languages are a contrast. What I was thinking is this: if functional programming languages cannot save any state, how do they do some simple stuff like reading input from a user (I mean how do they "store" it), or storing any data for that matter? For example - how would this simple C thing translate to any functional programming language, for example haskell? #include<stdio.h> int main() { int no; scanf("%d",&no); return 0; }

    Read the article

  • Cabal: Odd Error Message + Lack of Documentation

    - by voxcogitatio
    So I recently installed cabal (from the default binary of ArchLinux). I then tried to upgrade cabal as a user: cabal upgrade Cabal --user --prefix=$USER Resolving dependencies... cabal: fromFlag NoFlag. Use fromFlagOrDefault What I've already done: Googled the error message. Turned up the cabal source and little else. Looked at haskell-wiki on cabal-install. Looked through this guide. So basically I'm wondering: What's up with the error message? Could anyone point me in the direction of a cabal tutorial?

    Read the article

  • Threading extra state through a parser in Scala

    - by Travis Brown
    I'll give you the tl;dr up front I'm trying to use the state monad transformer in Scalaz 7 to thread extra state through a parser, and I'm having trouble doing anything useful without writing a lot of t m a -> t m b versions of m a -> m b methods. An example parsing problem Suppose I have a string containing nested parentheses with digits inside them: val input = "((617)((0)(32)))" I also have a stream of fresh variable names (characters, in this case): val names = Stream('a' to 'z': _*) I want to pull a name off the top of the stream and assign it to each parenthetical expression as I parse it, and then map that name to a string representing the contents of the parentheses, with the nested parenthetical expressions (if any) replaced by their names. To make this more concrete, here's what I'd want the output to look like for the example input above: val target = Map( 'a' -> "617", 'b' -> "0", 'c' -> "32", 'd' -> "bc", 'e' -> "ad" ) There may be either a string of digits or arbitrarily many sub-expressions at a given level, but these two kinds of content won't be mixed in a single parenthetical expression. To keep things simple, we'll assume that the stream of names will never contain either duplicates or digits, and that it will always contain enough names for our input. Using parser combinators with a bit of mutable state The example above is a slightly simplified version of the parsing problem in this Stack Overflow question. I answered that question with a solution that looked roughly like this: import scala.util.parsing.combinator._ class ParenParser(names: Iterator[Char]) extends RegexParsers { def paren: Parser[List[(Char, String)]] = "(" ~> contents <~ ")" ^^ { case (s, m) => (names.next -> s) :: m } def contents: Parser[(String, List[(Char, String)])] = "\\d+".r ^^ (_ -> Nil) | rep1(paren) ^^ ( ps => ps.map(_.head._1).mkString -> ps.flatten ) def parse(s: String) = parseAll(paren, s).map(_.toMap) } It's not too bad, but I'd prefer to avoid the mutable state. What I want Haskell's Parsec library makes adding user state to a parser trivially easy: import Control.Applicative ((*>), (<$>), (<*)) import Data.Map (fromList) import Text.Parsec paren = do (s, m) <- char '(' *> contents <* char ')' h : t <- getState putState t return $ (h, s) : m where contents = flip (,) [] <$> many1 digit <|> (\ps -> (map (fst . head) ps, concat ps)) <$> many1 paren main = print $ runParser (fromList <$> paren) ['a'..'z'] "example" "((617)((0)(32)))" This is a fairly straightforward translation of my Scala parser above, but without mutable state. What I've tried I'm trying to get as close to the Parsec solution as I can using Scalaz's state monad transformer, so instead of Parser[A] I'm working with StateT[Parser, Stream[Char], A]. I have a "solution" that allows me to write the following: import scala.util.parsing.combinator._ import scalaz._, Scalaz._ object ParenParser extends ExtraStateParsers[Stream[Char]] with RegexParsers { protected implicit def monadInstance = parserMonad(this) def paren: ESP[List[(Char, String)]] = (lift("(" ) ~> contents <~ lift(")")).flatMap { case (s, m) => get.flatMap( names => put(names.tail).map(_ => (names.head -> s) :: m) ) } def contents: ESP[(String, List[(Char, String)])] = lift("\\d+".r ^^ (_ -> Nil)) | rep1(paren).map( ps => ps.map(_.head._1).mkString -> ps.flatten ) def parse(s: String, names: Stream[Char]) = parseAll(paren.eval(names), s).map(_.toMap) } This works, and it's not that much less concise than either the mutable state version or the Parsec version. But my ExtraStateParsers is ugly as sin—I don't want to try your patience more than I already have, so I won't include it here (although here's a link, if you really want it). I've had to write new versions of every Parser and Parsers method I use above for my ExtraStateParsers and ESP types (rep1, ~>, <~, and |, in case you're counting). If I had needed to use other combinators, I'd have had to write new state transformer-level versions of them as well. Is there a cleaner way to do this? I'd love to see an example of a Scalaz 7's state monad transformer being used to thread state through a parser, but Scala 6 or Haskell examples would also be useful.

    Read the article

  • For reliable code, NModel, Spec Explorer, F# or other?

    - by ja
    I've got a business app in C#, with unit tests. Can I increase the reliability and cut down on my testing time and expense by using NModel or Spec Explorer? Alternately, if I were to rewrite it in F# (or even Haskell), what kinds (if any) of reliability increase might I see? Code Contracts? ASML? I realize this is subjective, and possibly argumentative, so please back up your answers with data, if possible. :) Or maybe an worked example, such as Eric Evans Cargo Shipping System? If we consider Unit tests to be pecific and strong theorems, checked quasi-statically on particular “interesting instances” and Types to be general but weak theorems (usually checked statically), and contracts to be general and strong theorems, checked dynamically for particular instances that occur during regular program operation (from B. Pierce's Types Considered Harmful, where do these other tools fit? We could pose the analogous question for Java, using Java PathFinder, Scala, etc.

    Read the article

  • Neural Network Always Produces Same/Similar Outputs for Any Input

    - by l33tnerd
    I have a problem where I am trying to create a neural network for Tic-Tac-Toe. However, for some reason, training the neural network causes it to produce nearly the same output for any given input. I did take a look at Artificial neural networks benchmark, but my network implementation is built for neurons with the same activation function for each neuron, i.e. no constant neurons. To make sure the problem wasn't just due to my choice of training set (1218 board states and moves generated by a genetic algorithm), I tried to train the network to reproduce XOR. The logistic activation function was used. Instead of using the derivative, I multiplied the error by output*(1-output) as some sources suggested that this was equivalent to using the derivative. I can put the Haskell source on HPaste, but it's a little embarrassing to look at. The network has 3 layers: the first layer has 2 inputs and 4 outputs, the second has 4 inputs and 1 output, and the third has 1 output. Increasing to 4 neurons in the second layer didn't help, and neither did increasing to 8 outputs in the first layer. I then calculated errors, network output, bias updates, and the weight updates by hand based on http://hebb.mit.edu/courses/9.641/2002/lectures/lecture04.pdf to make sure there wasn't an error in those parts of the code (there wasn't, but I will probably do it again just to make sure). Because I am using batch training, I did not multiply by x in equation (4) there. I am adding the weight change, though http://www.faqs.org/faqs/ai-faq/neural-nets/part2/section-2.html suggests to subtract it instead. The problem persisted, even in this simplified network. For example, these are the results after 500 epochs of batch training and of incremental training. Input |Target|Output (Batch) |Output(Incremental) [1.0,1.0]|[0.0] |[0.5003781562785173]|[0.5009731800870864] [1.0,0.0]|[1.0] |[0.5003740346965251]|[0.5006347214672715] [0.0,1.0]|[1.0] |[0.5003734471544522]|[0.500589332376345] [0.0,0.0]|[0.0] |[0.5003674110937019]|[0.500095157458231] Subtracting instead of adding produces the same problem, except everything is 0.99 something instead of 0.50 something. 5000 epochs produces the same result, except the batch-trained network returns exactly 0.5 for each case. (Heck, even 10,000 epochs didn't work for batch training.) Is there anything in general that could produce this behavior? Also, I looked at the intermediate errors for incremental training, and the although the inputs of the hidden/input layers varied, the error for the output neuron was always +/-0.12. For batch training, the errors were increasing, but extremely slowly and the errors were all extremely small (x10^-7). Different initial random weights and biases made no difference, either. Note that this is a school project, so hints/guides would be more helpful. Although reinventing the wheel and making my own network (in a language I don't know well!) was a horrible idea, I felt it would be more appropriate for a school project (so I know what's going on...in theory, at least. There doesn't seem to be a computer science teacher at my school). EDIT: Two layers, an input layer of 2 inputs to 8 outputs, and an output layer of 8 inputs to 1 output, produces much the same results: 0.5+/-0.2 (or so) for each training case. I'm also playing around with pyBrain, seeing if any network structure there will work. Edit 2: I am using a learning rate of 0.1. Sorry for forgetting about that. Edit 3: Pybrain's "trainUntilConvergence" doesn't get me a fully trained network, either, but 20000 epochs does, with 16 neurons in the hidden layer. 10000 epochs and 4 neurons, not so much, but close. So, in Haskell, with the input layer having 2 inputs & 2 outputs, hidden layer with 2 inputs and 8 outputs, and output layer with 8 inputs and 1 output...I get the same problem with 10000 epochs. And with 20000 epochs. Edit 4: I ran the network by hand again based on the MIT PDF above, and the values match, so the code should be correct unless I am misunderstanding those equations. Some of my source code is at http://hpaste.org/42453/neural_network__not_working; I'm working on cleaning my code somewhat and putting it in a Github (rather than a private Bitbucket) repository. All of the relevant source code is now at https://github.com/l33tnerd/hsann.

    Read the article

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