haskell

Stack's package.yaml vs stack.yaml

我与影子孤独终老i 提交于 2020-01-01 08:41:17
问题 Stack has supported hpack's package.yaml configuration files since at least around this commit, as far as I can tell, but there's not much documentation about the differences between it and the stack.yaml file. One of the few links I've found talking about it is this documentation, where it says: package.yaml is a file format supported by hpack. It adds some niceties on top of cabal. For example, hpack has YAML syntax support and will automatically generate of exposed-modules lists. However,

Displaying dynamically generated images in Yesod

亡梦爱人 提交于 2020-01-01 08:38:21
问题 I'm writing my first Yesod app. The application involves the user selecting to view a graph, dynamically generated based on data stored in a DB on the server. I know how to get the user request and create the image on the server's file system, but how do I create a response page presenting it? P.S. As I'm using GnuPlot to generate the image, I only know how to write it as a file to the file system, but If you happen to know how to get the data in memory it'll probably be even better. Thanks,

Using Haskell's types to replace assert statements or if checks in other languages

别等时光非礼了梦想. 提交于 2020-01-01 08:27:09
问题 Sorry if the question is very elementary, I am still very new to Haskell. Lets say I have a function that can only work with two numbers that are in the golden ration (1.618), how do I define the types of myfun x y to take only golden ratio numbers. What happens if I invoke myfun without golden ratio numbers from within my program (a compile error?)? What happens if the call without golden ratio numbers is made at runtime via user input? 回答1: You might want an ADT that can only be constructed

Linking a dynamic library (libjvm.dylib) in Mac OS X (rpath issue)

怎甘沉沦 提交于 2020-01-01 08:27:07
问题 I do have an application that requires linkage with libjvm (a library from the JDK needed to do JNI bindings). When I tell the location of libjvm.dylib using -L it successfully compiles and links. However when I run the binary I get: dyld: Library not loaded: @rpath/libjvm.dylib Referenced from: <my home directory>/./mybinary Reason: image not found So far I found out that I can run my binary specifying LD_LIBRARY_PATH like so: LD_LIBRARY_PATH=<path to libfolder installation> ./mybinary But

How does the constraints package work?

随声附和 提交于 2020-01-01 08:18:12
问题 The idea behind Data.Constraint.Forall, as I understand it, is to use coercion in the implementation, but ensure safety using the type system. I have two questions regarding the latter. Why do we need two skolem variables — A and B? I would imagine that if a constraint is satisfied by an «unknown» type, then it is polymorphic. How does the second type give more safety? Why are these types called skolem variables? I thought that skolemnization is used to remove existential quantification, and

How does the constraints package work?

断了今生、忘了曾经 提交于 2020-01-01 08:18:08
问题 The idea behind Data.Constraint.Forall, as I understand it, is to use coercion in the implementation, but ensure safety using the type system. I have two questions regarding the latter. Why do we need two skolem variables — A and B? I would imagine that if a constraint is satisfied by an «unknown» type, then it is polymorphic. How does the second type give more safety? Why are these types called skolem variables? I thought that skolemnization is used to remove existential quantification, and

Function Composition in R (and high level functions)

喜夏-厌秋 提交于 2020-01-01 08:03:57
问题 Is there something like a function composition in R? I think in haskell it's somthing like "(.)" and in agda it's the ring operator. Also, I find litte information on high level functional programming in R. I found the Functions "Reduce", "Map", "Filter"..., are there more? Any pointers? 回答1: You may make compositing function like this: composite<-function(f,g) function(...) f(g(...)) f<-function(x) x+1; g<-function(x) x*2; composite(f,g)(7) composite(g,f)(7) or make operator of this. About

C compiler selection in cabal package

南楼画角 提交于 2020-01-01 08:03:23
问题 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.). 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? I did found only CC-Options. 回答1: There really doesn't seem to be

Get a sublist in Haskell

丶灬走出姿态 提交于 2020-01-01 07:34:49
问题 Probably an easy one, but I've looked through the docs and googled for examples and I'm still not sure of the answer. If I have a list like this: [1,2,3,4,5,6,7,8,9,0] and I want to extract a slice, say from index 4 to index 8 i.e. I want: [5,6,7,8,9] What is the idiomatic way to do this in Haskell? 回答1: First of all, that's not an array, it's a list. I'm not being (merely) pedantic, as arrays are much more problematic in Haskell than lists. That said, one common way is to use take and drop

Installing & Building GHC with OSX Mavericks GHC

南笙酒味 提交于 2020-01-01 07:28:31
问题 Why doesn't my GHC 7.6.3 work after upgrading to OSX Mavericks? 回答1: It took a long time to figure out how to Work with both OSX 10.9 and GHC 7.6.3, and here are some tips to help you get back to building haskell code. Summary: Download command line tools for mavericks and use gcc version 4.2 (link to the correct gcc path in your ghc settings file) Steps: Download the command line tools for mavericks Install gcc-4.2 using homebrew brew install apple-gcc42 Edit your settings file, Line 2.