
I'm finding that in more than one instance I pass a data structure to a function, simply so that I can pass it to it's helper function. It bugs me that I'm passing a value that isn't being used directly. This seems wrong. Example: I have a "data URLSequence" that contains a way to calculate the ip address of a URL. This gets passed to a helper function that generates a particular URL, which then populates the URLSequence. Is there a standard practice to avoid what I am talking about? Or is this normal and I should accept it?

On 4 August 2011 23:53, Michael Litchard
I'm finding that in more than one instance I pass a data structure to a function, simply so that I can pass it to it's helper function. It bugs me that I'm passing a value that isn't being used directly. This seems wrong. Example: I have a "data URLSequence" that contains a way to calculate the ip address of a URL. This gets passed to a helper function that generates a particular URL, which then populates the URLSequence. Is there a standard practice to avoid what I am talking about? Or is this normal and I should accept it?
There is implicit parameters[1], but personally I bite the bullet in cases like this as it doesn't happen so often. [1] http://www.haskell.org/ghc/docs/7.0.3/html/users_guide/other-type-extensions...

Hi all, I tried using a database via haskell. The following simple test program could not be compiled via 'ghc Main.hs'. The output of ghc is: Main.o: In function `s1pB_info': (.text+0x6e): undefined reference to `HDBCzmpostgresqlzm2zi2zi3zi3_DatabaseziHDBCziPostgreSQLziConnectionImpl_zdfIConnectionConnection_closure' Main.o: In function `s1qt_info': (.text+0x169): undefined reference to `HDBCzmpostgresqlzm2zi2zi3zi3_DatabaseziHDBCziPostgreSQLziConnection_connectPostgreSQL_closure' Main.o: In function `s1qt_info': (.text+0x279): undefined reference to `__stginit_HDBCzm2zi2zi7zi0_DatabaseziHDBC_' Main.o: In function `s1qt_info': (.text+0x283): undefined reference to `__stginit_HDBCzmpostgresqlzm2zi2zi3zi3_DatabaseziHDBCziPostgreSQL_' Main.o: In function `s1pB_info': (.text+0x76): undefined reference to `HDBCzm2zi2zi7zi0_DatabaseziHDBCziTypes_disconnect_info' Main.o: In function `s1pC_srt': (.data+0x4): undefined reference to `HDBCzmpostgresqlzm2zi2zi3zi3_DatabaseziHDBCziPostgreSQLziConnectionImpl_zdfIConnectionConnection_closure' Main.o: In function `s1qt_srt': (.data+0x14): undefined reference to `HDBCzmpostgresqlzm2zi2zi3zi3_DatabaseziHDBCziPostgreSQLziConnection_connectPostgreSQL_closure' collect2: ld returned 1 exit status Is this a bug? Or do I need to modify the configuration of my system? If I load that module into ghci (':l Main') the compilation succeeds. % ghc --version: 'The Glorious Glasgow Haskell Compilation System, version 6.12.1' % psql --version: 'psql (PostgreSQL) 8.4.8 contains support for command-line editing' I also wanted to try out MySQL. I stranded much earlier: % cabal install database-hdbc-mysql: There is no such package, but shouldn't there be one? module Main where import Database.HDBC import Database.HDBC.PostgreSQL(connectPostgreSQL) main :: IO () main = do c <- connectPostgreSQL "host=localhost dbname=haskell user=gary password=wasauchimmer" disconnect c return () I would be glad about help! Greets Gary

On 5 August 2011 00:45, Gary Klindt
Hi all,
I tried using a database via haskell. The following simple test program could not be compiled via 'ghc Main.hs'. The output of ghc is:
You need to tell ghc what libraries to link. Try ghc --make Main.hs

On Thu, Aug 4, 2011 at 2:53 PM, Michael Litchard
I'm finding that in more than one instance I pass a data structure to a function, simply so that I can pass it to it's helper function. It bugs me that I'm passing a value that isn't being used directly. This seems wrong. Example: I have a "data URLSequence" that contains a way to calculate the ip address of a URL. This gets passed to a helper function that generates a particular URL, which then populates the URLSequence. Is there a standard practice to avoid what I am talking about? Or is this normal and I should accept it?
I think this is normal, and you should accept it. At least, assuming you're using the result of the helper function somewhere. You could "solve" this by hoisting the body of the helper function into the main function, but that sort of defeats the point of having the helper function.

On Thu, Aug 04, 2011 at 02:53:34PM -0700, Michael Litchard wrote:
I'm finding that in more than one instance I pass a data structure to a function, simply so that I can pass it to it's helper function. It bugs me that I'm passing a value that isn't being used directly. This seems wrong. Example: I have a "data URLSequence" that contains a way to calculate the ip address of a URL. This gets passed to a helper function that generates a particular URL, which then populates the URLSequence. Is there a standard practice to avoid what I am talking about? Or is this normal and I should accept it?
Others have answered the question in a way that seems to address your situation well. However, I thought I would also mention that in the case where there is a single piece of read-only data that needs to be annoyingly threaded through large parts of your code, you can use the Reader monad to make the threading implicit. But this solution is too heavyweight for some situations since it does require changing the code to use a monadic style. -Brent

Thanks Brent. I just may use a Reader monad in version 2 for the sake
of learning how to do it.
On Fri, Aug 5, 2011 at 6:51 AM, Brent Yorgey
On Thu, Aug 04, 2011 at 02:53:34PM -0700, Michael Litchard wrote:
I'm finding that in more than one instance I pass a data structure to a function, simply so that I can pass it to it's helper function. It bugs me that I'm passing a value that isn't being used directly. This seems wrong. Example: I have a "data URLSequence" that contains a way to calculate the ip address of a URL. This gets passed to a helper function that generates a particular URL, which then populates the URLSequence. Is there a standard practice to avoid what I am talking about? Or is this normal and I should accept it?
Others have answered the question in a way that seems to address your situation well. However, I thought I would also mention that in the case where there is a single piece of read-only data that needs to be annoyingly threaded through large parts of your code, you can use the Reader monad to make the threading implicit. But this solution is too heavyweight for some situations since it does require changing the code to use a monadic style.
-Brent
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

Michael Litchard wrote:
I'm finding that in more than one instance I pass a data structure to a function, simply so that I can pass it to it's helper function. It bugs me that I'm passing a value that isn't being used directly. This seems wrong. Example: I have a "data URLSequence" that contains a way to calculate the ip address of a URL. This gets passed to a helper function that generates a particular URL, which then populates the URLSequence. Is there a standard practice to avoid what I am talking about? Or is this normal and I should accept it?
An old blog post by Duncan Coutts describes how to eliminate some parameter passing with higher-order functions (essentially continuations): http://www.well-typed.com/blog/10 Best regards, Heinrich Apfelmus -- http://apfelmus.nfshost.com
participants (6)
-
Brent Yorgey
-
Christopher Done
-
Gary Klindt
-
Heinrich Apfelmus
-
Michael Litchard
-
Mike Meyer