Re: [Haskell-cafe] Package updates on haskell.org
byorgey: On Thu, Jun 5, 2008 at 6:47 PM, Don Stewart [EMAIL PROTECTED] wrote: The HWN, which I'm sadly too busy to maintain now, Does this imply that you're looking for someone to take over the HWN? I'd be willing. Yep, I've spoken with Brent. He's just starting his PhD, so a perfect candidate to take over the weekly news. More announcements to follow. Thanks for the offer , Brent! -- Don ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] FunPtr error?
Thanks. Clause? regards, Vasili On Mon, Jun 9, 2008 at 12:54 AM, Bulat Ziganshin [EMAIL PROTECTED] wrote: Hello Vasili, Monday, June 9, 2008, 6:17:14 AM, you wrote: 1. standard place to import FunPtr from is Foreign.Ptr, not System.Posix 2. FunPtr is exported as abstract type, without constructors. you can't construct values of this type directly. instead you should use wrapper generators as in the example that Clause has wrote. read it carefully :) Hello, I am getting what is to me a mysterious error in a test case that I am writing: [EMAIL PROTECTED]:~/FTP/Haskell/unix-2.2.0.0/tests/timer$ runhaskell Setup.lhs build Preprocessing executables for Test-1.0... Building Test-1.0... [1 of 1] Compiling Main ( ./timer.hs, dist/build/timer/timer-tmp/Main.o ) ./timer.hs:11:45: Not in scope: data constructor `FunPtr' It seems like the compiler is complaining about the lack of FunPtr in it's symbol table but System.Posix is imported: module Main where import System.Posix import Foreign import Foreign.C import Foreign.Ptr main = do let event = Sigevent{sigevFunction=(FunPtr (notifyFunc))} error here timerId - timerCreate Clock_Realtime Nothing timerDelete timerId return () notifyFunc :: Sigval - IO () notifyFunc sigval = do putStrLn timer POP!!! return () I am probably looking right at the answer and not seeing it. ?? Thanks, Vasili -- Best regards, Bulatmailto:[EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Quick question for a slow program
Lanny Ripple wrote: At least when I teased apart why the first one worked it looked heap-like. Each step of the foldr pulled off the smallest nonprime and merged the next two lists guaranteeing that the next smallest nonprime would be at the head of the next step. Well, there is heap and heap. It's true that the tree of calls to merge fulfills the heap property, see the following diagrams: mergebefore evaluation / \ 4 merge : / \ 6 9 merge : : / \ 8 12 25 merge : ... : / \ ... 30 49 ... : : ... ... 4 first element : merge / \ 6 9 : : 8merge :/ \ ... 1225 : : ... merge / \ 3049 : : ... merge / \ ... ... 4 first and second element : 6 : merge / \ 89 :: ... merge / \ 12 25 :: ... merge / \ 30 49 :: ... merge / \ ... ... and so on. But as you can see, the heap is not balanced, foldr1 merge only generates a linear chain of merge nodes. A balanced tree like merge / \ merge merge / \ / \ 4 9 25 49 : : : : ... ... ... ... would be better, except that we need a variant that with an infinite number of leaves. The function foldTree builds such a tree. There is also the complication that the heap bites its own tail in that the multiples of a prime, and hence the heap, are not available until the prime itself has been calculated from the heap. The People a data structure solves this. Regards, apfelmus ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Moving forall over type constructors
At first I'd like to thank Claus, Ryan, Edsko, Luke and Derek for their quite helpful replies to my previous thread. In the course of following their advice I encountered the problem of moving a forall quantifier over a wrapper type constructor. If I have newtype Wrapper a = Wrapper a and I instantiate Wrapper with a polymorphic type, then it is possible to move the quantifier outside: outside :: Wrapper (forall a. (t a)) - (forall a. Wrapper (t a)) outside(Wrapper x) = Wrapper x (surprisingly the code does not work with the implementation 'outside x = x'; I guess this is a ghc bug) However, the other way around does not work: inside :: (forall a. Wrapper (t a))- Wrapper (forall a. (t a)) inside x= x results in the following error: Couldn't match expected type `forall a. t a' against inferred type `t a' Expected type: Wrapper (forall a1. t a1) Inferred type: Wrapper (t a) In the expression: x In the definition of `inside': inside x = x Any ideas on how to make this work? Klaus ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Moving forall over type constructors
On Mon, Jun 09, 2008 at 03:20:33PM +0200, Klaus Ostermann wrote: At first I'd like to thank Claus, Ryan, Edsko, Luke and Derek for their quite helpful replies to my previous thread. In the course of following their advice I encountered the problem of moving a forall quantifier over a wrapper type constructor. If I have newtype Wrapper a = Wrapper a and I instantiate Wrapper with a polymorphic type, then it is possible to move the quantifier outside: outside :: Wrapper (forall a. (t a)) - (forall a. Wrapper (t a)) outside(Wrapper x) = Wrapper x (surprisingly the code does not work with the implementation 'outside x = x'; I guess this is a ghc bug) Not a bug; those two types are not the same. In the code you've given, ghc needs to find evidence that it can create a element of type (Wrapper (t a)) for any any; fortunately, it can do so because it has 'x', which can create a 't a' for any 'a'. inside :: (forall a. Wrapper (t a))- Wrapper (forall a. (t a)) inside x= x results in the following error: But here we have an argument that can return a Wrapper (t a) for any 'a'; that does *not* mean it can return a wrapper of a polymorphic type. If you think about 'a' as an actual argument, then you could pass 'Int' to get a Wrapper (t Int), Bool to get a wrapper (t Bool), or even (forall a. a - a) to get a Wrapper (t (forall a. a - a)), but no argument at all could make a Wrapper (forall a. t a). Edsko ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Moving forall over type constructors
But here we have an argument that can return a Wrapper (t a) for any 'a'; that does *not* mean it can return a wrapper of a polymorphic type. If you think about 'a' as an actual argument, then you could pass 'Int' to get a Wrapper (t Int), Bool to get a wrapper (t Bool), or even (forall a. a - a) to get a Wrapper (t (forall a. a - a)), but no argument at all could make a Wrapper (forall a. t a). I just found out that it *is* possible to implement the inside function, namely as follows: inside :: forall t. ((forall a. Wrapper (t a))- Wrapper (forall a. (t a))) inside x = Wrapper f where f :: forall a. (t a) f = unwrap x unwrap (Wrapper z) = z I guess this solves my problem. Sorry for bothering you with this question. I still find it a bit weird to write all these obfuscated identity functions to make the type checker happy, though. Klaus -- View this message in context: http://www.nabble.com/Moving-%22forall%22-over-type-constructors-tp17732668p17733353.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Design your modules for qualified import
[EMAIL PROTECTED] writes: null filter map lookup On the contrary, these are terrible names _because_ they conflict with the Prelude. I agree. One solution would be to stuff these into Data.List. It's okay if you highly encourage or effectively mandate qualified import, like Data.Map does. I think designing modules for qualified-only use is a mistake. I also think import lists get quite ugly, with multiple instances of import qualified Data.Set as S import Data.Set (Set) for multiple - sometimes even the majority - of modules. Add to this that people will assign a variation of abbreviations for modules, we quickly lose consistency. And - is there a way to make GHCi use aliased qualification? I find my self typing detailed taxonomies all the time there. For Haskell', I would relly like to have good, generic classes/interfaces for this, so that a) code becomes readable (including import lists), and b) code can be written more generically, and c) it becomes easier to switch between e.g. different string types. -k -- If I haven't seen further, it is by standing in the footprints of giants ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Moving forall over type constructors
On Mon, Jun 09, 2008 at 06:55:20AM -0700, Klaus Ostermann wrote: But here we have an argument that can return a Wrapper (t a) for any 'a'; that does *not* mean it can return a wrapper of a polymorphic type. If you think about 'a' as an actual argument, then you could pass 'Int' to get a Wrapper (t Int), Bool to get a wrapper (t Bool), or even (forall a. a - a) to get a Wrapper (t (forall a. a - a)), but no argument at all could make a Wrapper (forall a. t a). I just found out that it *is* possible to implement the inside function, namely as follows: inside :: forall t. ((forall a. Wrapper (t a))- Wrapper (forall a. (t a))) inside x = Wrapper f where f :: forall a. (t a) f = unwrap x unwrap (Wrapper z) = z I guess this solves my problem. Sorry for bothering you with this question. I still find it a bit weird to write all these obfuscated identity functions to make the type checker happy, though. As I said, the types are not isomorphic -- it you think of type parameters as arguments you will see why. Edsko ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Moving forall over type constructors
Hi, I just found out that it *is* possible to implement the inside function, namely as follows: inside :: forall t. ((forall a. Wrapper (t a))- Wrapper (forall a. (t a))) inside x = Wrapper f where f :: forall a. (t a) f = unwrap x unwrap (Wrapper z) = z I guess this solves my problem. Sorry for bothering you with this question. I still find it a bit weird to write all these obfuscated identity functions to make the type checker happy, though. As I said, the types are not isomorphic -- it you think of type parameters as arguments you will see why. I found these examples interesting, mostly because I don't understand it very well. So, I simplified Klaus' code a bit and derived the following: - {-# LANGUAGE Rank2Types #-} -- Wrapper newtype W a = W { unW :: a } inside :: ((forall a. W (t a))- W (forall a. (t a))) --inside (W x) = W x -- (a) FAILS --inside = W . unW -- (b) FAILS inside x = W (unW x) -- (c) WORKS - Can someone comment on the differences between the following in terms of type-checking or inference? Considering the errors I got, I'm guess the issue is the same for the pattern-matching (a) and the point-free (b) versions. Are there any pointers for developing a better understanding or intuition of this? Thanks, Sean ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] ANNOUNCE: hfann-01
Hi all, I'm pleased to announce the first release of the hfann module ( http://code.haskell.org/~oboudry/hfann/). This module is an interface to the Fast Artificial Neural Network (FANN) library (see http://leenissen.dk/fann/). This is an early release. At the moment the hfann module does not cover all the functions found in the FANN library but it should be useable to train and use simple Neural Networks. At least is can be used to run an equivalent of the Getting Started example found in http://leenissen.dk/fann/html/files2/gettingstarted-txt.html. The module was developped on Windows XP with GHC-6.8.2. The README should provide you with all required information to install this module. The haddock documentation should give enough information to get started using it. == Installation == Download version 2.0 of the FANN library from: http://leenissen.dk/fann/download.php and build it according to the instruction found on: http://leenissen.dk/fann/html/files2/installation-txt.html Get the hfann module darcs get http://code.haskell.org/~oboudry/hfann/ Build it using Cabal runghc Setup.lhs configure runghc Setup.lhs build runghc Setup.lhs haddock runghc Setup.lhs install == Examples == Training an ANN to the xor function: import HFANN main = do withStandardFann [2,3,1] $ \fann - do setActivationFunctionHidden fann fannSigmoidSymetric setActivationFunctionOutput fann fannSigmoidSymetric trainOnFile fann xor.data -- train data 2 -- max epochs 100-- epochs between reports 0.001 -- desired error saveFann fann xor.ann C:\Temp\Haskell\hfann\examples\xorTrain.exe Max epochs2. Desired error: 0.001000. Epochs1. Current error: 0.2503675520. Bit fail 4. Epochs 100. Current error: 0.0181358512. Bit fail 0. Epochs 169. Current error: 0.0009599295. Bit fail 0. Using the trained ANN on the 4 possible input values to the xor function (-1 = False, 1 = True). import HFANN main = do withSavedFann xor.ann $ \fann - do mapM_ (\x - runFann fann x = print) [[-1,-1],[-1,1],[1,-1],[1,1]] C:\Temp\Haskell\hfann\examples\xorUse.exe [-0.950566361876292] [0.9178714756661263] [0.9457588340834527] [-0.9482816646878051] The xor.data training data content: 4 2 1 -1 -1 -1 -1 1 1 1 -1 1 1 1 -1 The files for this example can be found in the examples/xor directory == Bug reports, suggestions and comments are welcome. You can send them directly to my e-mail address. Olivier. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Unable to hc-build ghc 6.6.1
I'm trying to do a registered hc-build on linux2.4 x86 with ghc 6.6.1. After fixing mk/bootstrap.mk to include -lncurses in HC_BOOT_LIBS to get past an undefined reference to tputs et al, I've gotten stuck with the following undefined reference error: == gmake all -wr; in /tmp/ghc-6.6.1/utils/runstdtest gmake[1]: Nothing to be done for `all'. Finished making all in runstdtest: 0 == gmake all -wr; in /tmp/ghc-6.6.1/utils/genapply gcc -o genapply -fno-defer-pop -fomit-frame-pointer -fno-builtin -DDONT_WANT_WIN32_DLL_SUPPORT -D__GLASGOW_HASKELL__=606 -O -I/tmp/ghc-6.6.1/includes -I/tmp/ghc-6.6.1/libraries/base/include -I/tmp/ghc-6.6.1/libraries/unix/include -I/tmp/ghc-6.6.1/libraries/parsec/include -I/tmp/ghc-6.6.1/libraries/readline/include-L/tmp/ghc-6.6.1/rts -L/tmp/ghc-6.6.1/libraries/base -L/tmp/ghc-6.6.1/libraries/base/cbits -L/tmp/ghc-6.6.1/libraries/haskell98 -L/tmp/ghc-6.6.1/libraries/parsec -L/tmp/ghc-6.6.1/libraries/regex-base -L/tmp/ghc-6.6.1/libraries/regex-compat -L/tmp/ghc-6.6.1/libraries/regex-posix -L/tmp/ghc-6.6.1/libraries/Cabal -L/tmp/ghc-6.6.1/libraries/template-haskell -L/tmp/ghc-6.6.1/libraries/readline -L/tmp/ghc-6.6.1/libraries/unix -L/tmp/ghc-6.6.1/libraries/unix/cbits -u base_GHCziBase_Izh_static_info -u base_GHCziBase_Czh_static_info -u base_GHCziFloat_Fzh_static_info -u base_GHCziFloat_Dzh_static_info -u base_GHCziPtr_Ptr_static_info -u base_GHCziWord_Wzh_static_info -u base_GHCziInt_I8zh_static_info -u base_GHCziInt_I16zh_static_info -u base_GHCziInt_I32zh_static_info -u base_GHCziInt_I64zh_static_info -u base_GHCziWord_W8zh_static_info -u base_GHCziWord_W16zh_static_info -u base_GHCziWord_W32zh_static_info -u base_GHCziWord_W64zh_static_info -u base_GHCziStable_StablePtr_static_info -u base_GHCziBase_Izh_con_info -u base_GHCziBase_Czh_con_info -u base_GHCziFloat_Fzh_con_info -u base_GHCziFloat_Dzh_con_info -u base_GHCziPtr_Ptr_con_info -u base_GHCziStable_StablePtr_con_info -u base_GHCziBase_False_closure -u base_GHCziBase_True_closure -u base_GHCziPack_unpackCString_closure -u base_GHCziIOBase_stackOverflow_closure -u base_GHCziIOBase_heapOverflow_closure -u base_GHCziIOBase_NonTermination_closure -u base_GHCziIOBase_BlockedOnDeadMVar_closure -u base_GHCziIOBase_Deadlock_closure -u base_GHCziWeak_runFinalizzerBatch_closure -u __stginit_Prelude GenApply.o -lHSreadline -lreadline -lHStemplate-haskell -lHSunix -lHSunix_cbits -lHSCabal -lHShaskell98 -lHSregex-compat -lHSregex-posix -lHSregex-base -lHSbase -lHSbase_cbits -lHSparsec -lHSrts -lgmp -lm -lncurses -ldl -lrt GenApply.o(.text+0x13a55): In function `s5cr_info': : undefined reference to `base_DataziList_zdsintersperse_info' GenApply.o(.text+0x14c11): In function `s58p_info': : undefined reference to `base_DataziList_zdsintersperse_info' GenApply.o(.text+0x17d79): In function `s54x_info': : undefined reference to `base_DataziList_zdsintersperse_info' collect2: ld returned 1 exit status gmake[1]: *** [genapply] Error 1 Failed making all in genapply: 1 gmake: *** [all] Error 1 gmake: Leaving directory `/tmp/ghc-6.6.1/utils' Does anyone know why this might be occuring? The only reference to base_DataziList_zdsintersperse_info on google didn't seem to have an answer. For reference my mk/build.mk is: SRC_HC_OPTS = -H32m -O -fvia-C -Rghc-timing -keep-hc-files GhcLibHcOpts= -O GhcLibWays = SplitObjs = NO just as the example one given on http://hackage.haskell.org/trac/ghc/wiki/Building/Porting. Also- in case this is related- I moved AutoApply_thr.thr_hc to AutoApply_thr.hc (and likewise for debug, thr_debug, and thr_p). Thanks, Joseph Re NOTICE: If received in error, please destroy and notify sender. Sender does not intend to waive confidentiality or privilege. Use of this email is prohibited when received in error. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANNOUNCE: hfann-01
On Mon, Jun 9, 2008 at 11:29 AM, Don Stewart [EMAIL PROTECTED] wrote: Excellent. Would you like to upload it to hackage.haskell.org, so it can be easily installed with the 'cabal install' tool? Hi all, As suggested by Don, I just uploaded the hfann package to hackage.haskell.org. It's available here: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/hfann Best regards, Olivier. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] FunPtr error?
In any case, what I want to do is store FunPtr in a data type and marshall into a C struct as a C function pointer. Vasili On Mon, Jun 9, 2008 at 1:24 AM, Galchin, Vasili [EMAIL PROTECTED] wrote: Thanks. Clause? regards, Vasili On Mon, Jun 9, 2008 at 12:54 AM, Bulat Ziganshin [EMAIL PROTECTED] wrote: Hello Vasili, Monday, June 9, 2008, 6:17:14 AM, you wrote: 1. standard place to import FunPtr from is Foreign.Ptr, not System.Posix 2. FunPtr is exported as abstract type, without constructors. you can't construct values of this type directly. instead you should use wrapper generators as in the example that Clause has wrote. read it carefully :) Hello, I am getting what is to me a mysterious error in a test case that I am writing: [EMAIL PROTECTED]:~/FTP/Haskell/unix-2.2.0.0/tests/timer$ runhaskell Setup.lhs build Preprocessing executables for Test-1.0... Building Test-1.0... [1 of 1] Compiling Main ( ./timer.hs, dist/build/timer/timer-tmp/Main.o ) ./timer.hs:11:45: Not in scope: data constructor `FunPtr' It seems like the compiler is complaining about the lack of FunPtr in it's symbol table but System.Posix is imported: module Main where import System.Posix import Foreign import Foreign.C import Foreign.Ptr main = do let event = Sigevent{sigevFunction=(FunPtr (notifyFunc))} error here timerId - timerCreate Clock_Realtime Nothing timerDelete timerId return () notifyFunc :: Sigval - IO () notifyFunc sigval = do putStrLn timer POP!!! return () I am probably looking right at the answer and not seeing it. ?? Thanks, Vasili -- Best regards, Bulatmailto:[EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Design your modules for qualified import
On Mon, 2008-06-09 at 16:04 +0200, Ketil Malde wrote: I think designing modules for qualified-only use is a mistake. I also think import lists get quite ugly, with multiple instances of import qualified Data.Set as S import Data.Set (Set) for multiple - sometimes even the majority - of modules. As far as I can see that is the only downside, having to import more than once to get the type name unqualified with the rest of the module qualified. Add to this that people will assign a variation of abbreviations for modules, we quickly lose consistency. The obvious consistent thing to do is to use the last part of the module name, at least for short names like Set and Map. For ByteString it is more of a mouthful. import qualified Data.Set as Set import Data.Set (Set) Set.empty, Set.insert etc etc. And - is there a way to make GHCi use aliased qualification? I find my self typing detailed taxonomies all the time there. The ghci syntax currently is: :m Data.Set wouldn't it be much nicer as: import Data.Set then we could have the obvious: import Data.Set as Set Duncan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] FunPtr error?
type Notify = Sigval - IO () foreign import ccall wrapper mkNotify :: Notify - IO (FunPtr Notify) then main = do notifyFPtr - mkNotify notifyFunc -- rest of code here -- then, when you are done and nothing is referencing the pointer any more freeHaskellFunPtr notifyFPtr On 6/9/08, Galchin, Vasili [EMAIL PROTECTED] wrote: In any case, what I want to do is store FunPtr in a data type and marshall into a C struct as a C function pointer. Vasili This will be suitable for that purpose. -- ryan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Design your modules for qualified import
* On Monday, June 09 2008, Duncan Coutts wrote: And - is there a way to make GHCi use aliased qualification? I find my self typing detailed taxonomies all the time there. The ghci syntax currently is: :m Data.Set wouldn't it be much nicer as: import Data.Set then we could have the obvious: import Data.Set as Set ghci does load modules when you type import Data.Set already, but it doesn't parse import Data.Set as Set ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Design your modules for qualified import
On Mon, Jun 9, 2008 at 4:04 PM, Ketil Malde [EMAIL PROTECTED] wrote: I think designing modules for qualified-only use is a mistake. I also think import lists get quite ugly, with multiple instances of I was only suggesting avoiding namespacing prefixes/suffixes in identifiers. Other than that things would be the same. You don't have to import things as qualified. However, if you're going to try to avoid using identifiers in your exported interface because they would collide with other modules I would advice against it. I agree with you that the module imports get a bit ugly. I prefer that to the alternative though. Add to this that people will assign a variation of abbreviations for modules, we quickly lose consistency. It's a shame that we have such deep hierarchies otherwise we wouldn't need to always alias out module imports. I think Python get's it right: import os ... os.tmpname ... Duncan's recommendation of just taking the part after the last dot seems like a good rule of thumb. Doing import qualified Data.Map as M does gain you much in my opinion. Compare M.empty to emptyM. No difference, you still can't deduce the module by just looking at the call site. Cheers, Johan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Design your modules for qualified import
Johan Tibell [EMAIL PROTECTED] writes: Duncan's recommendation of just taking the part after the last dot seems like a good rule of thumb. Doing import qualified Data.Map as M does gain you much in my opinion. Compare M.empty to emptyM. No difference, you still can't deduce the module by just looking at the call site. I would prefer `M.empty' to `emptyM'. At least, by looking at `M.empty', you know that this `empty' is from `M' and you can easily check out what `M' is from the import list. I personally always found myself unproductively tracing back something like `emptyM' to its origin. Cheers, Johan -- c/*__o/* \ * (__ */\ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Design your modules for qualified import
Excerpts from johan.tibell's message of Mon Jun 09 21:53:50 +0200 2008: On Mon, Jun 9, 2008 at 4:04 PM, Ketil Malde [EMAIL PROTECTED] wrote: I think designing modules for qualified-only use is a mistake. I also think import lists get quite ugly, with multiple instances of I was only suggesting avoiding namespacing prefixes/suffixes in identifiers. Other than that things would be the same. You don't have to import things as qualified. However, if you're going to try to avoid using identifiers in your exported interface because they would collide with other modules I would advice against it. I agree with you that the module imports get a bit ugly. I prefer that to the alternative though. Add to this that people will assign a variation of abbreviations for modules, we quickly lose consistency. It's a shame that we have such deep hierarchies otherwise we wouldn't need to always alias out module imports. I think Python get's it right: import os ... os.tmpname ... Duncan's recommendation of just taking the part after the last dot seems like a good rule of thumb. Doing import qualified Data.Map as M does gain you much in my opinion. Compare M.empty to emptyM. No difference, you still can't deduce the module by just looking at the call site. Coming from a world where qualified names at call sites or full import (open) are the default rules (OCaml), I much prefer the import way (where you specify names that gets imported) and thus prefer when names don't collide (except for modules like Data.Map or ByteString where I use the as notation). The key point for me is to be able to trace as fast as possible what precisely use a module by looking (only) at the top of the file. Best regards, -- Nicolas Pouillard aka Ertai signature.asc Description: PGP signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Design your modules for qualified import
On Thu, Jun 5, 2008 at 4:19 PM, Johan Tibell [EMAIL PROTECTED] wrote: * Why is this practice common in Haskell Here are some guesses: 1. It's common in papers. However, papers and libraries are quite different. The former usually build up a small vocabulary and having short names is a big win. Papers rarely make use of the module system at all. The latter are included as pieces of large programs and their names need to be adjusted accordingly. 2. It's the default. You have to add qualified to all your imports to make them qualified. In most language imports are qualified by default. I think the latter would have been a better choice but we have to live with the current design so bite the bullet and add those qualified keywords to your imports. 3. Lack of common interfaces. An example would be two different set implementations that essentially have the same interface but since there is no explicitly shared interface, defined using a type class, you sometimes end up with different names. The lack of type families might explain why e.g. collection classes don't share interfaces. 4. Haskell is a very expressive language. You can often write a whole function definition on one line! Adding those module qualifications makes your code slightly longer and it might just break your beautiful one liner into two lines. Another BIG reason: It's impossible to export a whole hierarchy qualified. I.e it would be neat if the user could write: import Graphics.UI.Gtk And then have Gtk re-export sub-modules qualified, so you could write Button.new, Window.new etc. etc. As it stands you have two options: prefix all the new functions with the kind of widget they create (buttonNew, windowNew), or force the user to add a gazillion qualified imports. Ideally you would be able to add qualified to the module export statement, and have it automatically bring in that module qualified (it should also support an as so you'd write qualified module Graphics.UI.Gtk.Button as Button in the export list to get the above behaviour.) -- Sebastian Sylvan +44(0)7857-300802 UIN: 44640862 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] File locking wishlist
Hi again, Am Donnerstag, den 05.06.2008, 17:22 +0200 schrieb Joachim Breitner: Hi, for a program of mine (darcswatch[1]), a rather long running process is run at certain events (by cron, and by new emails). I want to achieve that: * Only one instance of the program runs at a time. * If new events come in while the program runs, it should re-run itself * There is information attached to the events (only one Bool ATM) So I’d like to implement something with this, or a similar, interface: === module MyLocking where -- | tries to get the lock. If it fails, notifies the running process -- to re-start itself afterwards, with the given information -- returns True if the lock was aquired lockOrMark :: Show a = FilePath - a - IO Bool -- | release the lock. If new events have come in, they are returned -- in the list, and the lock is still kept. If the list is empty, -- the lock was successfully released. releaseLock :: Read a = FilePath - IO [a] === I wrote a module that provides this API. It can be found here: http://darcs.nomeata.de/darcswatch/src/LockRestart.hs I use it for darcswatch, you can see the relevant change here: http://darcs.nomeata.de/cgi-bin/darcsweb.cgi?r=darcswatch;a=filediff;h=20080609203612-23c07-aec8c4e1f22a9c3bdd44d062ab26f7d18a880a18.gz;f=src/Main.hs Actually, since only the call to or in the third changed line from the bottom is special to darcswatch, this can be moved into LockRestart, so the change to the program is reduced to this: config - read `fmap` readFile (confdir ++ config) + +lockRestart (cOutput config) patchNew or True (do_work config) + +do_work config patchNew = do putStrLn Reading repositories... or even config - read `fmap` readFile (confdir ++ config) + +lockRestart (cOutput config) patchNew or True $ \patchNew - do + putStrLn Reading repositories... if you prefer. Enjoy, Joachim Breitner -- Joachim Breitner e-Mail: [EMAIL PROTECTED] Homepage: http://www.joachim-breitner.de ICQ#: 74513189 Jabber-ID: [EMAIL PROTECTED] signature.asc Description: Dies ist ein digital signierter Nachrichtenteil ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] ANN: funsat 0.5, a SAT solver written in Haskell
Hi all, It is my pleasure to announce the first reasonable release of funsat, a modern, DPLL-style SAT solver written in Haskell. Funsat solves formulas in conjunctive normal form and produces a total variable assignment for satisfiable problems. It is available from Hackage: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/funsat http://churn.ath.cx/funsat.html As well as in a Git repo, which contains many benchmark files funsat can solve. git clone http://churn.ath.cx/funsat Funsat is intended to be reasonably efficient for practical problems and convenient to use as a constraint-solving backend in other software. The former is achieved by using several well-known techniques from the literature including two-watched literals, conflict-directed learning, non-chronological backtracking, a VSIDS-like dynamic variable ordering, and restarts. The latter is supported currently by efficient unsatisfiable core generation, which generates a minimal unsatisfiable problem for a given unsatisfiable problem. In the future, I plan to add support for converting boolean circuits into CNF, as well as support for other types of constraints. Please try it out and report bugs! (This email is the one listed on the website.) -- Denis ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] FunPtr error?
Ryan, I tried but the compiler didn't seem to like the keyword import: [EMAIL PROTECTED]:~/FTP/Haskell/unix-2.2.0.0/tests/timer$ runhaskell Setup.lhs build Preprocessing executables for Test-1.0... Building Test-1.0... [1 of 1] Compiling Main ( ./timer.hs, dist/build/timer/timer-tmp/Main.o ) ./timer.hs:29:8: parse error on input `import' source ...: module Main where import System.Posix import Foreign import Foreign.C import Foreign.Ptr type Notify = Sigval - IO () main = do notifyFPtr - mkNotify notifyFunc let event = Sigevent{sigevFunction=notifyFPtr} timerId - timerCreate Clock_Realtime Nothing timerDelete timerId return () notifyFunc :: Sigval - IO () notifyFunc sigval = do putStrLn timer POP!!! return () foreign import ccall wrapper mkNotify :: Notify - IO (FunPtr Notify) ~ Everything looks ok to me. ?? Regards, Vasili On Mon, Jun 9, 2008 at 2:16 PM, Ryan Ingram [EMAIL PROTECTED] wrote: type Notify = Sigval - IO () foreign import ccall wrapper mkNotify :: Notify - IO (FunPtr Notify) then main = do notifyFPtr - mkNotify notifyFunc -- rest of code here -- then, when you are done and nothing is referencing the pointer any more freeHaskellFunPtr notifyFPtr On 6/9/08, Galchin, Vasili [EMAIL PROTECTED] wrote: In any case, what I want to do is store FunPtr in a data type and marshall into a C struct as a C function pointer. Vasili This will be suitable for that purpose. -- ryan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] FunPtr error?
2008/6/9 Galchin, Vasili [EMAIL PROTECTED]: Ryan, I tried but the compiler didn't seem to like the keyword import: [EMAIL PROTECTED]:~/FTP/Haskell/unix-2.2.0.0/tests/timer$ runhaskell Setup.lhs build Preprocessing executables for Test-1.0... Building Test-1.0... [1 of 1] Compiling Main ( ./timer.hs, dist/build/timer/timer-tmp/Main.o ) ./timer.hs:29:8: parse error on input `import' Hi Vasili, To fix that error, you probably just need to add the line Extensions: ForeignFunctionInterface to the .cabal file. (That is the equivalent of calling ghc by itself with the command-line arguments -fffi or -XForeignFunctionInterface.) Hope that helps, -Judah ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] FunPtr error?
Thanks Judah ... getting closer now. Vasili On Mon, Jun 9, 2008 at 11:25 PM, Judah Jacobson [EMAIL PROTECTED] wrote: 2008/6/9 Galchin, Vasili [EMAIL PROTECTED]: Ryan, I tried but the compiler didn't seem to like the keyword import: [EMAIL PROTECTED]:~/FTP/Haskell/unix-2.2.0.0/tests/timer$ runhaskell Setup.lhs build Preprocessing executables for Test-1.0... Building Test-1.0... [1 of 1] Compiling Main ( ./timer.hs, dist/build/timer/timer-tmp/Main.o ) ./timer.hs:29:8: parse error on input `import' Hi Vasili, To fix that error, you probably just need to add the line Extensions: ForeignFunctionInterface to the .cabal file. (That is the equivalent of calling ghc by itself with the command-line arguments -fffi or -XForeignFunctionInterface.) Hope that helps, -Judah ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe