adding other files to haskell
Hello, Im writing app in haskell and I would like to export some functions and datatypes to other files and then be able to use them in my main file. How to do this ? thanks for help ...
Hello, Im writing app in haskell and I would like to export some functions and datatypes to other files and then be able to use them in my main file. How to do this ? thanks for help ...
Hi! Imagine we have to sources to be requested by ajax. I want to perform some actions when all callbacks are triggered. How this can be done besides this approach: (function($){ var sources = ['http://source1.com', 'http://source2.com'], guard = 0, someHandler = function() { if (guard != sources.length) { return; } //d...
Is there a functional-programming equivalent to the Gang of Four Design Patterns book? That is, is there a book that explains and gives examples of how commonly-needed code structures are implemented functionally? I think seeing that would give me a better idea of how to go about using in practice the functional concepts whose theory I...
Hi! I need to translate some code from Scheme to Common Lisp. Now, I have something like this: (defun sum (term a next b) (if (> a b) 0 (+ (term a) (sum term (next a) b)))) (defun sum-int (a b) (defun (ident x) x) (sum ident a 1+ b)) but it produces errors. * - DEFUN: the name of a function must be a symbol, not (I...
I am a lifelong object-oriented programmer. My job is primarily java development, but I have experience in a number of languages. Ruby gave me my first real taste of functional programming. I loved the features Ruby borrowed from the functional paradigm such as closures and continuations. Eventually, I graduated to Scala. This has be...
At just after 2:40 in ShadowofCatron's Scala Tutorial 3 video, it's pointed out that the parentheses following the name of a thunk are optional. "Buh?" said my functional programming brain, since the value of a function and the value it evaluates to when applied are completely different things. So I wrote the following to try this out....
In the folder function of the Array.Fold operation, i want to look back arbitrary number of items. The only way i can figure out is like this. let aFolder (dataArray, curIdx, result) (dataItem) = let N = numItemsToLookBack(result, dataItem) let recentNitems = dataArray.[curIdx - N .. curIdx - 1] let result = aCalc(r...
I'm really interested how lambda functions are used. Does it make sense to use them in a modern, high-level programming language like php? If yes, why? Is this really just a function embedded in a function (like this) or is there more behind them? ...
I am building some equations in F#, and when working on my polynomial class I found some odd behavior using List.mapi Basically, each polynomial has an array, so 3*x^2 + 5*x + 6 would be [|6, 5, 3|] in the array, so, when adding polynomials, if one array is longer than the other, then I just need to append the extra elements to the resu...
I have the following code: foo :: Int -> [String] -> [(FilePath, Integer)] -> IO Int foo _ [] _ = return 4 foo _ _ [] = return 5 foo n nameREs pretendentFilesWithSizes = do result <- (bar n (head nameREs) pretendentFilesWithSizes) if result == 0 then return 0 -- <========================================== here is the error else...
I'm using Java's DataInputStream with scala to parse some simple binary file (which is very bad exprerience due to the lack of unsigned types, even in scala, but that's a different story). However I find myself forced to use mutable data structure, since Java's streams are inherently state preserving entities. What's a good design to w...
Is there a Mathematica function like inject in Ruby? For example, if I want the product of the elements in a list, in Ruby I can write: list.inject(1) { |prod,el| prod * el } I found I can just use Product in Mathematica: Apply[Product, list] However, this isn't general enough for me (like, if I don't just want the product or sum o...
As far as I can see, the usual (and best in my opinion) order for teaching iterting constructs in functional programming with Scheme is to first teach recursion and maybe later get into things like map, reduce and all SRFI-1 procedures. This is probably, I guess, because with recursion the student has everything that's necessary for iter...
I came upon the Curry-Howard Isomorphism relatively late in my programming life, and perhaps this contributes to my being utterly fascinated by it. It implies that for every programming concept there exists a precise analogue in formal logic, and vice versa. Here's a "basic" list of such analogies, off the top of my head: program/defini...
I'm not sure exactly how much this falls under 'programming' opposed to 'program language design'. But the issue is this: Say, for sake of simplicity we have two 'special' lists/arrays/vectors/whatever we just call 'ports' for simplicity, one called stdIn and another stdOut. These conceptually represent respectively All the user input...
I have an haskell problem. putStrLn is supposed to take a [Char], or a String, and even though it seems like I give that to mr Compiler, he still complains. *** Expression : putStrLn line *** Term : line *** Type : Char *** Does not match : [Char] The code that it refers to is this: getV::[[(Char,Float)]] -> I...
I often need to pass methods from objects into other objects. However I usually want the method to be attached to the original object (by attached I mean 'this' should refer to the original object). I know a few ways to do this: a) In the object constructor: ObjectA = function() { var that = this; var method = function(a,b,c) { that.abc...
I see what seems like a majority of Python developers on StackOverflow endorsing the use of concise functional tools like lambdas, maps, filters, etc., while others say their code is clearer and more maintainable by not using them. What is your preference? Also, if you are a die-hard functional programmer or hardcore into OO, what othe...
Are there any open source projects out there that are written in a functional programming language and that people can contribute on? I am trying to increase my area of expertise to a functional programming language and I think contributing to a project might be the way to go. Maybe some OCaml or Lisp projects? ...
I'm not sure if 'architecture' is the correct term, but I've been looking for some articles online which talk about programming design and more about how best to use languages such as JavaScript in a code design sense rather than the actual syntax itself. I have found many websites but a lot seem to be very out dated, and I'm not sure w...