From charioteer7 at gmail.com Sun Mar 1 02:58:50 2015 From: charioteer7 at gmail.com (Geoffrey Bays) Date: Sat, 28 Feb 2015 21:58:50 -0500 Subject: [Haskell-beginners] Using findIndex and then splitAt in Data.List In-Reply-To: <54F1E431.7000704@orlitzky.com> References: <54F1CBEE.5050806@orlitzky.com> <54F1E431.7000704@orlitzky.com> Message-ID: Michael: Yes, a map with a function that leaves everything I do not want to change alone, that would indeed be the smooth, obvious FP way to do it. I will change my code to work this way. Thanks. Geoffrey On Feb 28, 2015 10:52 AM, "Michael Orlitzky" wrote: > On 02/28/2015 10:02 AM, Geoffrey Bays wrote: > > Michael: > > Thanks, split on would work nicely. > > > > I probably should have backed up in my reasoning process to say that my > > real task is to replace a data item in a list with another altered data > > item in the same position, or rather in FP, create a new list with the > > altered item in the same place. And I need a predicate to find the name > of > > the item I want to replace. > > Any thoughts? > > > > > You can define a function to "fix" the thing that you want to alter, and > then map that function over the list. Just make sure that the function > only alters the thing that you want to alter. For example, suppose the > other numbers are afraid of 7, so you want to change 7 into 8 in some list: > > -- Turn 7 into 8; leave everything else alone. > fix_seven :: Int -> Int > fix_seven 7 = 8 > fix_seven x = x > > numbers :: [Int] > numbers = [1..10] > > ghci> print $ map fix_seven numbers > [1,2,3,4,5,6,8,8,9,10] > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jakep at arqux.com Sun Mar 1 04:40:49 2015 From: jakep at arqux.com (DJ) Date: Sat, 28 Feb 2015 23:40:49 -0500 Subject: [Haskell-beginners] trying to install libraries for Haskell School of Expression Message-ID: <54F29851.9040202@arqux.com> Trying to install the package soegtk. I am running linux mint 17 with the latest (as of Feb. 28) haskell platform and cabal-install. I did install gtk2hs-buildtools and put the .cabal/bin in my path. Cannot install soegtk: Failed to install glib-0.12.5.4 cabal: Error: some packages failed to install: cairo-0.12.5.3 failed during the configure step. The exception was: ExitFailure 1 gio-0.12.5.3 depends on glib-0.12.5.4 which failed to install. glib-0.12.5.4 failed during the configure step. The exception was: ExitFailure 1 gtk-0.12.5.7 depends on glib-0.12.5.4 which failed to install. pango-0.12.5.3 depends on glib-0.12.5.4 which failed to install. soegtk-0.12.1 depends on glib-0.12.5.4 which failed to install. Confession: I abandoned Haskell two years ago because of frustration with cabal and hackage. I decided to get back to the language today, and to start with Haskell School of Expression. I immediately run into the problem that the first thing I try to install with cabal does not work. Thanks for any help. Please tell me things are not just as bad now as they were when I left ;-) - DJP - From sumit.sahrawat.apm13 at iitbhu.ac.in Sun Mar 1 05:52:38 2015 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Sun, 1 Mar 2015 11:22:38 +0530 Subject: [Haskell-beginners] trying to install libraries for Haskell School of Expression In-Reply-To: <54F29851.9040202@arqux.com> References: <54F29851.9040202@arqux.com> Message-ID: We have sandboxes now, which (I think) weren't there 2 yrs ago. Try this: $ mkdir hse # Directory for Haskell school of expression $ cd hse $ cabal sandbox init # Create a new sandbox $ cabal install gtk2hs-buildtools # Install gtk2hs-buildtools inside sandbox $ export PATH=".cabal-sandbox/bin:$PATH" # Add the binaries installed in (current directory's) sandbox to $PATH $ cabal install gtk # Install gtk (and anything else you need) The above works in my case. Also, if you have a lot of packages installed in "~/.cabal", then I recommend that you remove them and install them in sandboxes where they are actually required. Manually, you'd do it as follows: $ mv ~/.cabal/packages ~/temporary_package_storage # Long name to avoid clash, save downloaded package sources $ rm -rf ~/.ghc ~/.cabal # Remove all packages, and ghc's knowledge of them $ mkdir ~/.cabal # Make a new ~/.cabal directory $ mv ~/temporary_package_storage ~/.cabal/packages # Reinsert the saved downloaded package sources For more info, look here: https://www.haskell.org/cabal/users-guide/installing-packages.html#developing-with-sandboxes Also, after some time it becomes natural to deal with cabal. For example, I have that export line in my .zshrc. Thus the sandbox residing in current directory is always in my path. Also, a shell function that you may want to use. cabal-reset () { if [[ ! -d ~/.cabal-packages ]] ; then # If backup does not exist mv ~/.cabal/packages ~/.cabal-packages # Make a backup fi rm -rf ~/.ghc ~/.cabal # Nuke everything mkdir ~/.cabal # Create new ~/.cabal ln -s ~/.cabal-packages ~/.cabal/packages # Symlink backup to ~/.cabal/packages } Hope this helps. On 1 March 2015 at 10:10, DJ wrote: > Trying to install the package soegtk. > > I am running linux mint 17 with the latest (as of Feb. 28) haskell > platform and cabal-install. > > I did install gtk2hs-buildtools and put the .cabal/bin in my path. > > Cannot install soegtk: > > Failed to install glib-0.12.5.4 > cabal: Error: some packages failed to install: > cairo-0.12.5.3 failed during the configure step. The exception was: > ExitFailure 1 > gio-0.12.5.3 depends on glib-0.12.5.4 which failed to install. > glib-0.12.5.4 failed during the configure step. The exception was: > ExitFailure 1 > gtk-0.12.5.7 depends on glib-0.12.5.4 which failed to install. > pango-0.12.5.3 depends on glib-0.12.5.4 which failed to install. > soegtk-0.12.1 depends on glib-0.12.5.4 which failed to install. > > Confession: I abandoned Haskell two years ago because of frustration with > cabal and hackage. I decided to get back to the language today, and to > start with Haskell School of Expression. I immediately run into the problem > that the first thing I try to install with cabal does not work. > > Thanks for any help. Please tell me things are not just as bad now as they > were when I left ;-) > > - DJP - > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -- Regards Sumit Sahrawat -------------- next part -------------- An HTML attachment was scrubbed... URL: From allbery.b at gmail.com Sun Mar 1 07:29:54 2015 From: allbery.b at gmail.com (Brandon Allbery) Date: Sun, 1 Mar 2015 02:29:54 -0500 Subject: [Haskell-beginners] trying to install libraries for Haskell School of Expression In-Reply-To: <54F29851.9040202@arqux.com> References: <54F29851.9040202@arqux.com> Message-ID: On Sat, Feb 28, 2015 at 11:40 PM, DJ wrote: > I am running linux mint 17 with the latest (as of Feb. 28) haskell > platform and cabal-install. > I did install gtk2hs-buildtools and put the .cabal/bin in my path. > Do you have the devel libraries needed by gtk installed? cabal cannot install them for you, and the runtime libraries are not sufficient. You'll want libcairo2-dev for this, and others for other gtk components (notably libgtk-3-dev but there will be others as well). -- brandon s allbery kf8nh sine nomine associates allbery.b at gmail.com ballbery at sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From magnus at therning.org Sun Mar 1 08:30:35 2015 From: magnus at therning.org (Magnus Therning) Date: Sun, 1 Mar 2015 09:30:35 +0100 Subject: [Haskell-beginners] trees on Haskell : Do I understand it right ? In-Reply-To: <54EF2732.90005@home.nl> References: <54EF1DCF.40906@home.nl> <54EF2732.90005@home.nl> Message-ID: <20150301083035.GA3078@tatooine> Roelof, please consider changing your mail client to send *both* HTML and plain-text emails! With your current setting you send *only* HTML sometimes and it results in a slightly broken list archive, see [1] for an example of the result. To boot, you also make it more difficult for those of us who use plain-text mail clients to benefit from the diskussions you participate in. /M [1]: https://mail.haskell.org/pipermail/beginners/2015-February/014808.html On Thu, Feb 26, 2015 at 03:01:22PM +0100, Roelof Wobben wrote: > > > http-equiv="Content-Type"> > > >
Oke,
>
> So a leaf is a node which has no "branch"
>
> I have made a exercise where I have to made the? logMessages.
> Now I have to turn them into a tree
>
> Where does the second entry goes then ?
>
> Roelof
>
>
> Konstantine Rybnikov schreef op 26-2-2015 om 14:56:
>
>
cite="mid:CAAbahfQO5o+Db_qy_B+vb3E6WWb1bdeQBmpAPa6E-5TwTjerjg at mail.gmail.com" > type="cite"> >
>
>
>
>
>
>
>
Hi Roelof,
>
>
> I think you misunderstood it.
>
>
>
There are two things here: types and values > (value-constructors). They exist in different world, > not touching each other.
>
>
>
In Haskell, you define a type as:
>
>
>
data <Type_Name> = > <ValueConstructor_Name> <Type_Name> > <Type_Name> <Type_Name>
>
>
>
You can create values as:
>
>
>
let varName = <ValueConstructor_Name> > <Value> <Value> <Value>
>
>
>
You need to put <Value> of some type, not > type name itself in place of those <Value>s.
>
>
>
So, with datatype you provided, you have two > data-constructors:
>
>
>
Leaf
>
>
>
and
>
>
>
Node <val> <val> <val>
>
>
>
You can create a leaf:
>
>
>
let leaf = Leav
>
>
>
or a node:
>
>
>
let node = Node Leaf "msg" Leaf
>
>
>
You can see that Node is a data-constructor that > takes 3 values, not type-names as it's parameters.
>
>
>
Hope this helps.
>
>
>
>
>
>
>
>

>
On Thu, Feb 26, 2015 at 3:21 PM, Roelof > Wobben < href="mailto:r.wobben at home.nl" target="_blank">r.wobben at home.nl> > wrote:
>
Hello,
>
> Suppose we have this definition of a tree :
>
> data MessageTree = Leaf
> ? ? ? ? ? ? ? ? ?| Node MessageTree LogMessage MessageTree
> ? deriving (Show, Eq)
>
> let Message? = LogMessage "E 1 this is a test error"
> let Message = LogMessage "e 2 this is the second test error > "
>
> As I understand it right I can make the first entry like > this : first_entry = Node Messagetree? Message Messagetree
>
> And the second one like this second_entry = Node Message > Messagetree Message2 Messagetree ??
>
> Roelof
>
> _______________________________________________
> Beginners mailing list
> href="mailto:Beginners at haskell.org" target="_blank">Beginners at haskell.org
> href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" > target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
>
>
>
>
>
>
_______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> 
>
>
> > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -- Magnus Therning OpenPGP: 0xAB4DFBA4 email: magnus at therning.org jabber: magnus at therning.org twitter: magthe http://therning.org/magnus Heuristic is an algorithm in a clown suit. It?s less predictable, it?s more fun, and it comes without a 30-day, money-back guarantee. -- Steve McConnell, Code Complete -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 163 bytes Desc: not available URL: From joel.neely at gmail.com Sun Mar 1 13:45:24 2015 From: joel.neely at gmail.com (Joel Neely) Date: Sun, 1 Mar 2015 07:45:24 -0600 Subject: [Haskell-beginners] trees on Haskell : Do I understand it right ? In-Reply-To: <54EF66A5.5050107@home.nl> References: <54EF1DCF.40906@home.nl> <54EF2732.90005@home.nl> <54EF307A.40204@home.nl> <54EF66A5.5050107@home.nl> Message-ID: Roelof, Perhaps it would help for you to draw diagrams for the cases you're working. If a leaf has nothing below it, and a node always has exactly three things below it (the left child, the message, and the right child), what would your picture look like for 1, 2, and 3 nodes? And how would you write out constructor expressions that match those shapes? Hope that helps, -jn- On Thu, Feb 26, 2015 at 12:32 PM, Roelof Wobben wrote: > Oke, > > I send it a second time but now in plain text. > > So for 3 it will be like this : > > Node = Node (Node Leaf "msg1" Leaf) (Node Leaf "msg2") (Node "msg3" > Leaf) ??? > > > Roelof > > > > > > Konstantine Rybnikov schreef op 26-2-2015 om 15:08: > > In my second example you can see a minimal node with a message: > > node = Node Leaf "msg" Leaf > > Instead of either left or right Leaf you can put another value of type > MessageTree, for example: > > node = Node Leaf "msg1" (Node Leaf "msg2" Leaf) > > On Thu, Feb 26, 2015 at 4:01 PM, Roelof Wobben wrote: > >> Oke, >> >> So a leaf is a node which has no "branch" >> >> I have made a exercise where I have to made the logMessages. >> Now I have to turn them into a tree >> >> Where does the second entry goes then ? >> >> Roelof >> >> >> Konstantine Rybnikov schreef op 26-2-2015 om 14:56: >> >> Hi Roelof, >> >> I think you misunderstood it. >> >> There are two things here: types and values (value-constructors). They >> exist in different world, not touching each other. >> >> In Haskell, you define a type as: >> >> data = >> >> >> You can create values as: >> >> let varName = >> >> You need to put of some type, not type name itself in place of >> those s. >> >> So, with datatype you provided, you have two data-constructors: >> >> Leaf >> >> and >> >> Node >> >> You can create a leaf: >> >> let leaf = Leav >> >> or a node: >> >> let node = Node Leaf "msg" Leaf >> >> You can see that Node is a data-constructor that takes 3 values, not >> type-names as it's parameters. >> >> Hope this helps. >> >> On Thu, Feb 26, 2015 at 3:21 PM, Roelof Wobben wrote: >> >>> Hello, >>> >>> Suppose we have this definition of a tree : >>> >>> data MessageTree = Leaf >>> | Node MessageTree LogMessage MessageTree >>> deriving (Show, Eq) >>> >>> let Message = LogMessage "E 1 this is a test error" >>> let Message = LogMessage "e 2 this is the second test error " >>> >>> As I understand it right I can make the first entry like this : >>> first_entry = Node Messagetree Message Messagetree >>> >>> And the second one like this second_entry = Node Message Messagetree >>> Message2 Messagetree ?? >>> >>> Roelof >>> >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >> >> >> >> _______________________________________________ >> Beginners mailing listBeginners at haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> > > > _______________________________________________ > Beginners mailing listBeginners at haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -- Beauty of style and harmony and grace and good rhythm depend on simplicity. - Plato -------------- next part -------------- An HTML attachment was scrubbed... URL: From objitsu at gmail.com Sun Mar 1 14:56:44 2015 From: objitsu at gmail.com (emacstheviking) Date: Sun, 1 Mar 2015 14:56:44 +0000 Subject: [Haskell-beginners] trying to install libraries for Haskell School of Expression In-Reply-To: <54F29851.9040202@arqux.com> References: <54F29851.9040202@arqux.com> Message-ID: I feel your pain... > Confession: I abandoned Haskell two years ago because of frustration with > cabal and hackage. I decided to get back to the language today, and to > start with Haskell School of Expression. I immediately run into the problem > that the first thing I try to install with cabal does not work. > > It is the same reason I have stopped using it. It's a real shame. Those with better education and understanding than mine should be concerned that the uptake of the language is stunted by its package manager. I love Haskell. I have taught myself (the beginnings at least) of group theory just to better comprehend the mindset of monads. For that alone I am glad I learned Haskell as it has rekindled my interest in maths! > Thanks for any help. Please tell me things are not just as bad now as they > were when I left ;-) > > This mail seems to indicate to me that "cabal hell" is here for some time to come... -------------- next part -------------- An HTML attachment was scrubbed... URL: From r.wobben at home.nl Sun Mar 1 18:08:22 2015 From: r.wobben at home.nl (Roelof Wobben) Date: Sun, 01 Mar 2015 19:08:22 +0100 Subject: [Haskell-beginners] trees on Haskell : Do I understand it right ? In-Reply-To: References: <54EF1DCF.40906@home.nl> <54EF2732.90005@home.nl> <54EF307A.40204@home.nl> <54EF66A5.5050107@home.nl> Message-ID: <54F35596.3060001@home.nl> Hello, Im looking for goofd online software to make the diagrams. As soon as I find it . I will publish them on the ML. Roelof Joel Neely schreef op 1-3-2015 om 14:45: > Roelof, > > Perhaps it would help for you to draw diagrams for the cases you're > working. > If a leaf has nothing below it, and a node always has exactly three > things below it (the left child, the message, and the right child), > what would your picture look like for 1, 2, and 3 nodes? > And how would you write out constructor expressions that match those > shapes? > > Hope that helps, > -jn- > > > On Thu, Feb 26, 2015 at 12:32 PM, Roelof Wobben > wrote: > > Oke, > > I send it a second time but now in plain text. > > So for 3 it will be like this : > > Node = Node (Node Leaf "msg1" Leaf) (Node Leaf "msg2") (Node > "msg3" Leaf) ??? > > > Roelof > > > >> >> >> Konstantine Rybnikov schreef op 26-2-2015 om 15:08: >>> In my second example you can see a minimal node with a message: >>> >>> node = Node Leaf "msg" Leaf >>> >>> Instead of either left or right Leaf you can put another value >>> of type MessageTree, for example: >>> >>> node = Node Leaf "msg1" (Node Leaf "msg2" Leaf) >>> >>> On Thu, Feb 26, 2015 at 4:01 PM, Roelof Wobben >> > wrote: >>> >>> Oke, >>> >>> So a leaf is a node which has no "branch" >>> >>> I have made a exercise where I have to made the logMessages. >>> Now I have to turn them into a tree >>> >>> Where does the second entry goes then ? >>> >>> Roelof >>> >>> >>> Konstantine Rybnikov schreef op 26-2-2015 om 14:56: >>>> Hi Roelof, >>>> >>>> I think you misunderstood it. >>>> >>>> There are two things here: types and values >>>> (value-constructors). They exist in different world, not >>>> touching each other. >>>> >>>> In Haskell, you define a type as: >>>> >>>> data = >>>> >>>> >>>> You can create values as: >>>> >>>> let varName = >>>> >>>> You need to put of some type, not type name itself >>>> in place of those s. >>>> >>>> So, with datatype you provided, you have two data-constructors: >>>> >>>> Leaf >>>> >>>> and >>>> >>>> Node >>>> >>>> You can create a leaf: >>>> >>>> let leaf = Leav >>>> >>>> or a node: >>>> >>>> let node = Node Leaf "msg" Leaf >>>> >>>> You can see that Node is a data-constructor that takes 3 >>>> values, not type-names as it's parameters. >>>> >>>> Hope this helps. >>>> >>>> On Thu, Feb 26, 2015 at 3:21 PM, Roelof Wobben >>>> > wrote: >>>> >>>> Hello, >>>> >>>> Suppose we have this definition of a tree : >>>> >>>> data MessageTree = Leaf >>>> | Node MessageTree LogMessage MessageTree >>>> deriving (Show, Eq) >>>> >>>> let Message = LogMessage "E 1 this is a test error" >>>> let Message = LogMessage "e 2 this is the second test >>>> error " >>>> >>>> As I understand it right I can make the first entry >>>> like this : first_entry = Node Messagetree Message >>>> Messagetree >>>> >>>> And the second one like this second_entry = Node >>>> Message Messagetree Message2 Messagetree ?? >>>> >>>> Roelof >>>> >>>> _______________________________________________ >>>> Beginners mailing list >>>> Beginners at haskell.org >>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>> >>>> >>>> >>>> >>>> _______________________________________________ >>>> Beginners mailing list >>>> Beginners at haskell.org >>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >>> >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >>> >>> >>> >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > > > -- > Beauty of style and harmony and grace and good rhythm depend on > simplicity. - Plato > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From r.wobben at home.nl Sun Mar 1 19:02:42 2015 From: r.wobben at home.nl (Roelof Wobben) Date: Sun, 01 Mar 2015 20:02:42 +0100 Subject: [Haskell-beginners] trees on Haskell : Do I understand it right ? In-Reply-To: <54F35596.3060001@home.nl> References: <54EF1DCF.40906@home.nl> <54EF2732.90005@home.nl> <54EF307A.40204@home.nl> <54EF66A5.5050107@home.nl> <54F35596.3060001@home.nl> Message-ID: <54F36252.10809@home.nl> Here the diagram for 1 messages : http://imgur.com/yuzXUNB In haskell it would be Node Message1 leaf leaf Roelof Roelof Wobben schreef op 1-3-2015 om 19:08: > Hello, > > Im looking for goofd online software to make the diagrams. > As soon as I find it . I will publish them on the ML. > > Roelof > > Joel Neely schreef op 1-3-2015 om 14:45: >> Roelof, >> >> Perhaps it would help for you to draw diagrams for the cases you're >> working. >> If a leaf has nothing below it, and a node always has exactly three >> things below it (the left child, the message, and the right child), >> what would your picture look like for 1, 2, and 3 nodes? >> And how would you write out constructor expressions that match those >> shapes? >> >> Hope that helps, >> -jn- >> >> >> On Thu, Feb 26, 2015 at 12:32 PM, Roelof Wobben > > wrote: >> >> Oke, >> >> I send it a second time but now in plain text. >> >> So for 3 it will be like this : >> >> Node = Node (Node Leaf "msg1" Leaf) (Node Leaf "msg2") (Node >> "msg3" Leaf) ??? >> >> >> Roelof >> >> >> >>> >>> >>> Konstantine Rybnikov schreef op 26-2-2015 om 15:08: >>>> In my second example you can see a minimal node with a message: >>>> >>>> node = Node Leaf "msg" Leaf >>>> >>>> Instead of either left or right Leaf you can put another value >>>> of type MessageTree, for example: >>>> >>>> node = Node Leaf "msg1" (Node Leaf "msg2" Leaf) >>>> >>>> On Thu, Feb 26, 2015 at 4:01 PM, Roelof Wobben >>> > wrote: >>>> >>>> Oke, >>>> >>>> So a leaf is a node which has no "branch" >>>> >>>> I have made a exercise where I have to made the logMessages. >>>> Now I have to turn them into a tree >>>> >>>> Where does the second entry goes then ? >>>> >>>> Roelof >>>> >>>> >>>> Konstantine Rybnikov schreef op 26-2-2015 om 14:56: >>>>> Hi Roelof, >>>>> >>>>> I think you misunderstood it. >>>>> >>>>> There are two things here: types and values >>>>> (value-constructors). They exist in different world, not >>>>> touching each other. >>>>> >>>>> In Haskell, you define a type as: >>>>> >>>>> data = >>>>> >>>>> >>>>> You can create values as: >>>>> >>>>> let varName = >>>>> >>>>> You need to put of some type, not type name itself >>>>> in place of those s. >>>>> >>>>> So, with datatype you provided, you have two >>>>> data-constructors: >>>>> >>>>> Leaf >>>>> >>>>> and >>>>> >>>>> Node >>>>> >>>>> You can create a leaf: >>>>> >>>>> let leaf = Leav >>>>> >>>>> or a node: >>>>> >>>>> let node = Node Leaf "msg" Leaf >>>>> >>>>> You can see that Node is a data-constructor that takes 3 >>>>> values, not type-names as it's parameters. >>>>> >>>>> Hope this helps. >>>>> >>>>> On Thu, Feb 26, 2015 at 3:21 PM, Roelof Wobben >>>>> > wrote: >>>>> >>>>> Hello, >>>>> >>>>> Suppose we have this definition of a tree : >>>>> >>>>> data MessageTree = Leaf >>>>> | Node MessageTree LogMessage >>>>> MessageTree >>>>> deriving (Show, Eq) >>>>> >>>>> let Message = LogMessage "E 1 this is a test error" >>>>> let Message = LogMessage "e 2 this is the second test >>>>> error " >>>>> >>>>> As I understand it right I can make the first entry >>>>> like this : first_entry = Node Messagetree Message >>>>> Messagetree >>>>> >>>>> And the second one like this second_entry = Node >>>>> Message Messagetree Message2 Messagetree ?? >>>>> >>>>> Roelof >>>>> >>>>> _______________________________________________ >>>>> Beginners mailing list >>>>> Beginners at haskell.org >>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>>> >>>>> >>>>> >>>>> >>>>> _______________________________________________ >>>>> Beginners mailing list >>>>> Beginners at haskell.org >>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>> >>>> >>>> _______________________________________________ >>>> Beginners mailing list >>>> Beginners at haskell.org >>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>> >>>> >>>> >>>> >>>> _______________________________________________ >>>> Beginners mailing list >>>> Beginners at haskell.org >>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >> >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> >> >> >> -- >> Beauty of style and harmony and grace and good rhythm depend on >> simplicity. - Plato >> >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > From jakep at arqux.com Sun Mar 1 19:27:51 2015 From: jakep at arqux.com (DJ) Date: Sun, 01 Mar 2015 14:27:51 -0500 Subject: [Haskell-beginners] trying to install libraries for Haskell School of Expression In-Reply-To: References: <54F29851.9040202@arqux.com> Message-ID: <54F36837.5090704@arqux.com> Yeah. I think there are a lot of us out there. I won't rant (much) here, because I hope to get some help from time to time. Alienating people is not a good way to get help. But: There are many things I like about the language, but I have always been perplexed by the haskell ecosystem in a couple of ways. However good and/or interesting a language might be, it is not possible to do meat and potatoes development unless there is a good supply of packages/libraries. My first problem was that I often just could not get stuff to install. The second problem was documentation. I hope it has improved a bit. I was always flabbergasted at the (apparent) belief that a few lines of API documentation coughed out by haddock are enough. But that's all there was in a lot of cases. That, and "refer to xxxx research paper" and "figure it out from the types". Hah. Any math paper that consisted of just the equations sorted in alphabetical order would not be well received, I think. I really admired that fact that Michael Snoyman wrote a book about Yesod. For all I know he may not have kept the book up, but at least he realized that people needed an explanation of how to use his software. Well, back to work. I am going to give haskell another try for sure. It's just too tempting to give up on. If it doesn't work, the next stop will be sml or ocaml. Best, - DJ - On 15-03-01 09:56 AM, emacstheviking wrote: > I feel your pain... > > Confession: I abandoned Haskell two years ago because of > frustration with cabal and hackage. I decided to get back to the > language today, and to start with Haskell School of Expression. I > immediately run into the problem that the first thing I try to > install with cabal does not work. > > It is the same reason I have stopped using it. It's a real shame. > Those with better education and understanding than mine should be > concerned that the uptake of the language is stunted by its package > manager. > > I love Haskell. I have taught myself (the beginnings at least) of > group theory just to better comprehend the mindset of monads. For that > alone I am glad I learned Haskell as it has rekindled my interest in > maths! > > Thanks for any help. Please tell me things are not just as bad now > as they were when I left ;-) > > This mail seems to indicate to me that "cabal hell" is here for some > time to come... > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: From jakep at arqux.com Sun Mar 1 19:31:58 2015 From: jakep at arqux.com (DJ) Date: Sun, 01 Mar 2015 14:31:58 -0500 Subject: [Haskell-beginners] trying to install libraries for Haskell School of Expression In-Reply-To: References: <54F29851.9040202@arqux.com> Message-ID: <54F3692E.40107@arqux.com> Brandon: Thanks. I did have to install some gtk libraries. I am also working in a sandbox now. This moved things ahead somewhat. But I am getting this now from 'cabal install soegtk': Graphics/SOE/Gtk.hs:94:18: Could not find module `System.Time' It is a member of the hidden package `old-time-1.1.0.1'. Perhaps you need to add `old-time' to the build-depends in your .cabal file. Use -v to see a list of the files searched for. Failed to install soegtk-0.9.12.2 I have forgotten anything I once knew about using cabal. I apologize for not learning how to deal with the above on my own, but I am hoping to get over this hump as quickly and painlessly as possible so I don't lose my momentum getting back to Haskell. So, can anyone give me a hint how to fix the above? Best, - DJ - On 15-03-01 02:29 AM, Brandon Allbery wrote: > On Sat, Feb 28, 2015 at 11:40 PM, DJ > wrote: > > I am running linux mint 17 with the latest (as of Feb. 28) haskell > platform and cabal-install. > I did install gtk2hs-buildtools and put the .cabal/bin in my path. > > > Do you have the devel libraries needed by gtk installed? cabal cannot > install them for you, and the runtime libraries are not sufficient. > You'll want libcairo2-dev for this, and others for other gtk > components (notably libgtk-3-dev but there will be others as well). > > -- > brandon s allbery kf8nh sine nomine associates > allbery.b at gmail.com > ballbery at sinenomine.net > unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: From thbach at students.uni-mainz.de Sun Mar 1 20:07:52 2015 From: thbach at students.uni-mainz.de (Thomas Bach) Date: Sun, 1 Mar 2015 21:07:52 +0100 Subject: [Haskell-beginners] trying to install libraries for Haskell School of Expression In-Reply-To: <54F3692E.40107@arqux.com> (DJ's message of "Sun, 1 Mar 2015 14:31:58 -0500") References: <54F29851.9040202@arqux.com> <54F3692E.40107@arqux.com> Message-ID: <87h9u4qy5j.fsf@ilxwinb01.fritz.box> DJ writes: > Graphics/SOE/Gtk.hs:94:18: > Could not find module `System.Time' > It is a member of the hidden package `old-time-1.1.0.1'. > Perhaps you need to add `old-time' to the build-depends in your .cabal > file. That is actually all you have to do: in the cabal file of your package you have either a 'library' section or an 'executable' section. These should have a field 'build-depends' simply add 'old-time >= 1.1 && < 1.2' their. See for example the cabal file of the lens package: https://github.com/ekmett/lens/blob/master/lens.cabal If you don't have a cabal file you can initialize one via 'cabal init' or simply install the package in the sandbox via running 'cabal install old-time-1.1' in your sandbox, i.e. the directory you ran 'cabal sandbox init' beforehand. Regards Thomas. From allbery.b at gmail.com Sun Mar 1 20:11:11 2015 From: allbery.b at gmail.com (Brandon Allbery) Date: Sun, 1 Mar 2015 15:11:11 -0500 Subject: [Haskell-beginners] trying to install libraries for Haskell School of Expression In-Reply-To: <54F3692E.40107@arqux.com> References: <54F29851.9040202@arqux.com> <54F3692E.40107@arqux.com> Message-ID: On Sun, Mar 1, 2015 at 2:31 PM, DJ wrote: > Brandon: Thanks. I did have to install some gtk libraries. I am also > working in a sandbox now. This moved things ahead somewhat. But I am > getting this now from 'cabal install soegtk': > > Graphics/SOE/Gtk.hs:94:18: > Could not find module `System.Time' > It is a member of the hidden package `old-time-1.1.0.1'. > That would be an out of date [program referring to the old time component (which wasn't very good, but was in base so didn't need dependencies). Just adding a dependency on old-time to the cabal file should be sufficient to get it to work. I don't know why soegtk hasn't been updated to either reference that package or use the modern time package. -- brandon s allbery kf8nh sine nomine associates allbery.b at gmail.com ballbery at sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From jakep at arqux.com Sun Mar 1 21:43:53 2015 From: jakep at arqux.com (DJ) Date: Sun, 01 Mar 2015 16:43:53 -0500 Subject: [Haskell-beginners] trying to install libraries for Haskell School of Expression In-Reply-To: <54F29851.9040202@arqux.com> References: <54F29851.9040202@arqux.com> Message-ID: <54F38819.3030304@arqux.com> Thanks for the help, guys. Life is short. I have spent the better part of two days trying to get soegtk to install. No luck. Same shit as when I left haskell behind two years ago. I'm out. - DJ - On 15-02-28 11:40 PM, DJ wrote: > Trying to install the package soegtk. > > I am running linux mint 17 with the latest (as of Feb. 28) haskell > platform and cabal-install. > > I did install gtk2hs-buildtools and put the .cabal/bin in my path. > > Cannot install soegtk: > > Failed to install glib-0.12.5.4 > cabal: Error: some packages failed to install: > cairo-0.12.5.3 failed during the configure step. The exception was: > ExitFailure 1 > gio-0.12.5.3 depends on glib-0.12.5.4 which failed to install. > glib-0.12.5.4 failed during the configure step. The exception was: > ExitFailure 1 > gtk-0.12.5.7 depends on glib-0.12.5.4 which failed to install. > pango-0.12.5.3 depends on glib-0.12.5.4 which failed to install. > soegtk-0.12.1 depends on glib-0.12.5.4 which failed to install. > > Confession: I abandoned Haskell two years ago because of frustration > with cabal and hackage. I decided to get back to the language today, > and to start with Haskell School of Expression. I immediately run into > the problem that the first thing I try to install with cabal does not > work. > > Thanks for any help. Please tell me things are not just as bad now as > they were when I left ;-) > > - DJP - > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > From sean at objitsu.com Mon Mar 2 11:46:05 2015 From: sean at objitsu.com (emacstheviking) Date: Mon, 2 Mar 2015 11:46:05 +0000 Subject: [Haskell-beginners] trying to install libraries for Haskell School of Expression In-Reply-To: <54F36837.5090704@arqux.com> References: <54F29851.9040202@arqux.com> <54F36837.5090704@arqux.com> Message-ID: Agreed. I will "finish" with a mild semi-demi-rant too regarding the assumption by a lot of posters that we are all academics with access to papers on this and that. I am not and I don't. If you cite a paper, make sure it's available to Joe Public please! As for only sticking to plain vanialla simple Haskell, yes, that works BUT there are some many great libraries that a real time savers...it's such a shame when they won't play well together! So, despite it all, tonight I will be hacking Haskell ! :) On 1 March 2015 at 19:27, DJ wrote: > Yeah. I think there are a lot of us out there. I won't rant (much) here, > because I hope to get some help from time to time. Alienating people is not > a good way to get help. > > But: > > There are many things I like about the language, but I have always been > perplexed by the haskell ecosystem in a couple of ways. However good and/or > interesting a language might be, it is not possible to do meat and potatoes > development unless there is a good supply of packages/libraries. > > My first problem was that I often just could not get stuff to install. The > second problem was documentation. I hope it has improved a bit. I was > always flabbergasted at the (apparent) belief that a few lines of API > documentation coughed out by haddock are enough. But that's all there was > in a lot of cases. That, and "refer to xxxx research paper" and "figure it > out from the types". Hah. Any math paper that consisted of just the > equations sorted in alphabetical order would not be well received, I think. > > I really admired that fact that Michael Snoyman wrote a book about Yesod. > For all I know he may not have kept the book up, but at least he realized > that people needed an explanation of how to use his software. > > Well, back to work. I am going to give haskell another try for sure. It's > just too tempting to give up on. If it doesn't work, the next stop will be > sml or ocaml. > > Best, > > - DJ - > > > On 15-03-01 09:56 AM, emacstheviking wrote: > > I feel your pain... > > >> Confession: I abandoned Haskell two years ago because of frustration with >> cabal and hackage. I decided to get back to the language today, and to >> start with Haskell School of Expression. I immediately run into the problem >> that the first thing I try to install with cabal does not work. >> >> It is the same reason I have stopped using it. It's a real shame. Those > with better education and understanding than mine should be concerned that > the uptake of the language is stunted by its package manager. > > I love Haskell. I have taught myself (the beginnings at least) of group > theory just to better comprehend the mindset of monads. For that alone I am > glad I learned Haskell as it has rekindled my interest in maths! > > > >> Thanks for any help. Please tell me things are not just as bad now as >> they were when I left ;-) >> >> This mail seems to indicate to me that "cabal hell" is here for some > time to come... > > > > > _______________________________________________ > Beginners mailing listBeginners at haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From julian.birch at gmail.com Mon Mar 2 12:10:20 2015 From: julian.birch at gmail.com (Julian Birch) Date: Mon, 2 Mar 2015 12:10:20 +0000 Subject: [Haskell-beginners] trying to install libraries for Haskell School of Expression In-Reply-To: References: <54F29851.9040202@arqux.com> <54F36837.5090704@arqux.com> Message-ID: Just a small note: if you're suffering from cabal hell, LTS Haskell may help you. I described how to use it here: http://www.colourcoding.net/blog/archive/2015/02/22/hello-world-web-application-in-haskell.aspx Hope someone finds it useful. J On Monday, March 2, 2015, emacstheviking wrote: > Agreed. I will "finish" with a mild semi-demi-rant too regarding the > assumption by a lot of posters that we are all academics with access to > papers on this and that. I am not and I don't. If you cite a paper, make > sure it's available to Joe Public please! > > As for only sticking to plain vanialla simple Haskell, yes, that works BUT > there are some many great libraries that a real time savers...it's such a > shame when they won't play well together! > > So, despite it all, tonight I will be hacking Haskell ! > > :) > > > On 1 March 2015 at 19:27, DJ > wrote: > >> Yeah. I think there are a lot of us out there. I won't rant (much) here, >> because I hope to get some help from time to time. Alienating people is not >> a good way to get help. >> >> But: >> >> There are many things I like about the language, but I have always been >> perplexed by the haskell ecosystem in a couple of ways. However good and/or >> interesting a language might be, it is not possible to do meat and potatoes >> development unless there is a good supply of packages/libraries. >> >> My first problem was that I often just could not get stuff to install. >> The second problem was documentation. I hope it has improved a bit. I was >> always flabbergasted at the (apparent) belief that a few lines of API >> documentation coughed out by haddock are enough. But that's all there was >> in a lot of cases. That, and "refer to xxxx research paper" and "figure it >> out from the types". Hah. Any math paper that consisted of just the >> equations sorted in alphabetical order would not be well received, I think. >> >> I really admired that fact that Michael Snoyman wrote a book about Yesod. >> For all I know he may not have kept the book up, but at least he realized >> that people needed an explanation of how to use his software. >> >> Well, back to work. I am going to give haskell another try for sure. It's >> just too tempting to give up on. If it doesn't work, the next stop will be >> sml or ocaml. >> >> Best, >> >> - DJ - >> >> >> On 15-03-01 09:56 AM, emacstheviking wrote: >> >> I feel your pain... >> >> >>> Confession: I abandoned Haskell two years ago because of frustration >>> with cabal and hackage. I decided to get back to the language today, and to >>> start with Haskell School of Expression. I immediately run into the problem >>> that the first thing I try to install with cabal does not work. >>> >>> It is the same reason I have stopped using it. It's a real shame. >> Those with better education and understanding than mine should be concerned >> that the uptake of the language is stunted by its package manager. >> >> I love Haskell. I have taught myself (the beginnings at least) of group >> theory just to better comprehend the mindset of monads. For that alone I am >> glad I learned Haskell as it has rekindled my interest in maths! >> >> >> >>> Thanks for any help. Please tell me things are not just as bad now as >>> they were when I left ;-) >>> >>> This mail seems to indicate to me that "cabal hell" is here for some >> time to come... >> >> >> >> >> _______________________________________________ >> Beginners mailing listBeginners at haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> > -- Sent from an iPhone, please excuse brevity and typos. -------------- next part -------------- An HTML attachment was scrubbed... URL: From sean at objitsu.com Mon Mar 2 12:21:54 2015 From: sean at objitsu.com (emacstheviking) Date: Mon, 2 Mar 2015 12:21:54 +0000 Subject: [Haskell-beginners] trying to install libraries for Haskell School of Expression In-Reply-To: References: <54F29851.9040202@arqux.com> <54F36837.5090704@arqux.com> Message-ID: Took a while to sink in....DEF trying this out tonight Looks AWESOME if it does what it says! Getting excited about Haskell again. THANKS!!!! Yoohoo :) On 2 March 2015 at 12:10, Julian Birch wrote: > Just a small note: if you're suffering from cabal hell, LTS Haskell may > help you. I described how to use it here: > > > http://www.colourcoding.net/blog/archive/2015/02/22/hello-world-web-application-in-haskell.aspx > > Hope someone finds it useful. > > J > > > On Monday, March 2, 2015, emacstheviking wrote: > >> Agreed. I will "finish" with a mild semi-demi-rant too regarding the >> assumption by a lot of posters that we are all academics with access to >> papers on this and that. I am not and I don't. If you cite a paper, make >> sure it's available to Joe Public please! >> >> As for only sticking to plain vanialla simple Haskell, yes, that works >> BUT there are some many great libraries that a real time savers...it's such >> a shame when they won't play well together! >> >> So, despite it all, tonight I will be hacking Haskell ! >> >> :) >> >> >> On 1 March 2015 at 19:27, DJ wrote: >> >>> Yeah. I think there are a lot of us out there. I won't rant (much) >>> here, because I hope to get some help from time to time. Alienating people >>> is not a good way to get help. >>> >>> But: >>> >>> There are many things I like about the language, but I have always been >>> perplexed by the haskell ecosystem in a couple of ways. However good and/or >>> interesting a language might be, it is not possible to do meat and potatoes >>> development unless there is a good supply of packages/libraries. >>> >>> My first problem was that I often just could not get stuff to install. >>> The second problem was documentation. I hope it has improved a bit. I was >>> always flabbergasted at the (apparent) belief that a few lines of API >>> documentation coughed out by haddock are enough. But that's all there was >>> in a lot of cases. That, and "refer to xxxx research paper" and "figure it >>> out from the types". Hah. Any math paper that consisted of just the >>> equations sorted in alphabetical order would not be well received, I think. >>> >>> I really admired that fact that Michael Snoyman wrote a book about >>> Yesod. For all I know he may not have kept the book up, but at least he >>> realized that people needed an explanation of how to use his software. >>> >>> Well, back to work. I am going to give haskell another try for sure. >>> It's just too tempting to give up on. If it doesn't work, the next stop >>> will be sml or ocaml. >>> >>> Best, >>> >>> - DJ - >>> >>> >>> On 15-03-01 09:56 AM, emacstheviking wrote: >>> >>> I feel your pain... >>> >>> >>>> Confession: I abandoned Haskell two years ago because of frustration >>>> with cabal and hackage. I decided to get back to the language today, and to >>>> start with Haskell School of Expression. I immediately run into the problem >>>> that the first thing I try to install with cabal does not work. >>>> >>>> It is the same reason I have stopped using it. It's a real shame. >>> Those with better education and understanding than mine should be concerned >>> that the uptake of the language is stunted by its package manager. >>> >>> I love Haskell. I have taught myself (the beginnings at least) of >>> group theory just to better comprehend the mindset of monads. For that >>> alone I am glad I learned Haskell as it has rekindled my interest in maths! >>> >>> >>> >>>> Thanks for any help. Please tell me things are not just as bad now as >>>> they were when I left ;-) >>>> >>>> This mail seems to indicate to me that "cabal hell" is here for some >>> time to come... >>> >>> >>> >>> >>> _______________________________________________ >>> Beginners mailing listBeginners at haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >>> >>> >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >>> >> > > -- > Sent from an iPhone, please excuse brevity and typos. > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From julian.birch at gmail.com Mon Mar 2 12:34:07 2015 From: julian.birch at gmail.com (Julian Birch) Date: Mon, 2 Mar 2015 12:34:07 +0000 Subject: [Haskell-beginners] trying to install libraries for Haskell School of Expression In-Reply-To: References: <54F29851.9040202@arqux.com> <54F36837.5090704@arqux.com> Message-ID: It gets better: they run a hoogle for the exact version, with every library. :) On Monday, March 2, 2015, emacstheviking wrote: > Took a while to sink in....DEF trying this out tonight > Looks AWESOME if it does what it says! > Getting excited about Haskell again. > THANKS!!!! Yoohoo :) > > > On 2 March 2015 at 12:10, Julian Birch > wrote: > >> Just a small note: if you're suffering from cabal hell, LTS Haskell may >> help you. I described how to use it here: >> >> >> http://www.colourcoding.net/blog/archive/2015/02/22/hello-world-web-application-in-haskell.aspx >> >> Hope someone finds it useful. >> >> J >> >> >> On Monday, March 2, 2015, emacstheviking > > wrote: >> >>> Agreed. I will "finish" with a mild semi-demi-rant too regarding the >>> assumption by a lot of posters that we are all academics with access to >>> papers on this and that. I am not and I don't. If you cite a paper, make >>> sure it's available to Joe Public please! >>> >>> As for only sticking to plain vanialla simple Haskell, yes, that works >>> BUT there are some many great libraries that a real time savers...it's such >>> a shame when they won't play well together! >>> >>> So, despite it all, tonight I will be hacking Haskell ! >>> >>> :) >>> >>> >>> On 1 March 2015 at 19:27, DJ wrote: >>> >>>> Yeah. I think there are a lot of us out there. I won't rant (much) >>>> here, because I hope to get some help from time to time. Alienating people >>>> is not a good way to get help. >>>> >>>> But: >>>> >>>> There are many things I like about the language, but I have always been >>>> perplexed by the haskell ecosystem in a couple of ways. However good and/or >>>> interesting a language might be, it is not possible to do meat and potatoes >>>> development unless there is a good supply of packages/libraries. >>>> >>>> My first problem was that I often just could not get stuff to install. >>>> The second problem was documentation. I hope it has improved a bit. I was >>>> always flabbergasted at the (apparent) belief that a few lines of API >>>> documentation coughed out by haddock are enough. But that's all there was >>>> in a lot of cases. That, and "refer to xxxx research paper" and "figure it >>>> out from the types". Hah. Any math paper that consisted of just the >>>> equations sorted in alphabetical order would not be well received, I think. >>>> >>>> I really admired that fact that Michael Snoyman wrote a book about >>>> Yesod. For all I know he may not have kept the book up, but at least he >>>> realized that people needed an explanation of how to use his software. >>>> >>>> Well, back to work. I am going to give haskell another try for sure. >>>> It's just too tempting to give up on. If it doesn't work, the next stop >>>> will be sml or ocaml. >>>> >>>> Best, >>>> >>>> - DJ - >>>> >>>> >>>> On 15-03-01 09:56 AM, emacstheviking wrote: >>>> >>>> I feel your pain... >>>> >>>> >>>>> Confession: I abandoned Haskell two years ago because of frustration >>>>> with cabal and hackage. I decided to get back to the language today, and to >>>>> start with Haskell School of Expression. I immediately run into the problem >>>>> that the first thing I try to install with cabal does not work. >>>>> >>>>> It is the same reason I have stopped using it. It's a real shame. >>>> Those with better education and understanding than mine should be concerned >>>> that the uptake of the language is stunted by its package manager. >>>> >>>> I love Haskell. I have taught myself (the beginnings at least) of >>>> group theory just to better comprehend the mindset of monads. For that >>>> alone I am glad I learned Haskell as it has rekindled my interest in maths! >>>> >>>> >>>> >>>>> Thanks for any help. Please tell me things are not just as bad now as >>>>> they were when I left ;-) >>>>> >>>>> This mail seems to indicate to me that "cabal hell" is here for some >>>> time to come... >>>> >>>> >>>> >>>> >>>> _______________________________________________ >>>> Beginners mailing listBeginners at haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>> >>>> >>>> >>>> _______________________________________________ >>>> Beginners mailing list >>>> Beginners at haskell.org >>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>> >>>> >>> >> >> -- >> Sent from an iPhone, please excuse brevity and typos. >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> > -- Sent from an iPhone, please excuse brevity and typos. -------------- next part -------------- An HTML attachment was scrubbed... URL: From sean at objitsu.com Mon Mar 2 12:44:38 2015 From: sean at objitsu.com (emacstheviking) Date: Mon, 2 Mar 2015 12:44:38 +0000 Subject: [Haskell-beginners] trying to install libraries for Haskell School of Expression In-Reply-To: References: <54F29851.9040202@arqux.com> <54F36837.5090704@arqux.com> Message-ID: What does that do for me within LTS confines? I know Hoogle, but I don't understand what you mean by "they run a hoogle for the exact version, with every library." ...I just want to understand so I can be as excited as everybody else right now! LOL :) On 2 March 2015 at 12:34, Julian Birch wrote: > > It gets better: they run a hoogle for the exact version, with every > library. :) > > On Monday, March 2, 2015, emacstheviking wrote: > >> Took a while to sink in....DEF trying this out tonight >> Looks AWESOME if it does what it says! >> Getting excited about Haskell again. >> THANKS!!!! Yoohoo :) >> >> >> On 2 March 2015 at 12:10, Julian Birch wrote: >> >>> Just a small note: if you're suffering from cabal hell, LTS Haskell may >>> help you. I described how to use it here: >>> >>> >>> http://www.colourcoding.net/blog/archive/2015/02/22/hello-world-web-application-in-haskell.aspx >>> >>> Hope someone finds it useful. >>> >>> J >>> >>> >>> On Monday, March 2, 2015, emacstheviking wrote: >>> >>>> Agreed. I will "finish" with a mild semi-demi-rant too regarding the >>>> assumption by a lot of posters that we are all academics with access to >>>> papers on this and that. I am not and I don't. If you cite a paper, make >>>> sure it's available to Joe Public please! >>>> >>>> As for only sticking to plain vanialla simple Haskell, yes, that works >>>> BUT there are some many great libraries that a real time savers...it's such >>>> a shame when they won't play well together! >>>> >>>> So, despite it all, tonight I will be hacking Haskell ! >>>> >>>> :) >>>> >>>> >>>> On 1 March 2015 at 19:27, DJ wrote: >>>> >>>>> Yeah. I think there are a lot of us out there. I won't rant (much) >>>>> here, because I hope to get some help from time to time. Alienating people >>>>> is not a good way to get help. >>>>> >>>>> But: >>>>> >>>>> There are many things I like about the language, but I have always >>>>> been perplexed by the haskell ecosystem in a couple of ways. However good >>>>> and/or interesting a language might be, it is not possible to do meat and >>>>> potatoes development unless there is a good supply of packages/libraries. >>>>> >>>>> My first problem was that I often just could not get stuff to install. >>>>> The second problem was documentation. I hope it has improved a bit. I was >>>>> always flabbergasted at the (apparent) belief that a few lines of API >>>>> documentation coughed out by haddock are enough. But that's all there was >>>>> in a lot of cases. That, and "refer to xxxx research paper" and "figure it >>>>> out from the types". Hah. Any math paper that consisted of just the >>>>> equations sorted in alphabetical order would not be well received, I think. >>>>> >>>>> I really admired that fact that Michael Snoyman wrote a book about >>>>> Yesod. For all I know he may not have kept the book up, but at least he >>>>> realized that people needed an explanation of how to use his software. >>>>> >>>>> Well, back to work. I am going to give haskell another try for sure. >>>>> It's just too tempting to give up on. If it doesn't work, the next stop >>>>> will be sml or ocaml. >>>>> >>>>> Best, >>>>> >>>>> - DJ - >>>>> >>>>> >>>>> On 15-03-01 09:56 AM, emacstheviking wrote: >>>>> >>>>> I feel your pain... >>>>> >>>>> >>>>>> Confession: I abandoned Haskell two years ago because of frustration >>>>>> with cabal and hackage. I decided to get back to the language today, and to >>>>>> start with Haskell School of Expression. I immediately run into the problem >>>>>> that the first thing I try to install with cabal does not work. >>>>>> >>>>>> It is the same reason I have stopped using it. It's a real shame. >>>>> Those with better education and understanding than mine should be concerned >>>>> that the uptake of the language is stunted by its package manager. >>>>> >>>>> I love Haskell. I have taught myself (the beginnings at least) of >>>>> group theory just to better comprehend the mindset of monads. For that >>>>> alone I am glad I learned Haskell as it has rekindled my interest in maths! >>>>> >>>>> >>>>> >>>>>> Thanks for any help. Please tell me things are not just as bad now as >>>>>> they were when I left ;-) >>>>>> >>>>>> This mail seems to indicate to me that "cabal hell" is here for >>>>> some time to come... >>>>> >>>>> >>>>> >>>>> >>>>> _______________________________________________ >>>>> Beginners mailing listBeginners at haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>>> >>>>> >>>>> >>>>> _______________________________________________ >>>>> Beginners mailing list >>>>> Beginners at haskell.org >>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>>> >>>>> >>>> >>> >>> -- >>> Sent from an iPhone, please excuse brevity and typos. >>> >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >>> >> > > -- > Sent from an iPhone, please excuse brevity and typos. > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From julian.birch at gmail.com Mon Mar 2 12:48:44 2015 From: julian.birch at gmail.com (Julian Birch) Date: Mon, 2 Mar 2015 12:48:44 +0000 Subject: [Haskell-beginners] trying to install libraries for Haskell School of Expression In-Reply-To: References: <54F29851.9040202@arqux.com> <54F36837.5090704@arqux.com> Message-ID: If you go to www.stackage.com/lts/1.10, you'll find a hoogle search box. It'll give you search results for everything in LTS 1.10. On Monday, March 2, 2015, emacstheviking wrote: > What does that do for me within LTS confines? I know Hoogle, but I don't > understand what you mean by "they run a hoogle for the exact version, > with every library." ...I just want to understand so I can be as excited as > everybody else right now! LOL :) > > > On 2 March 2015 at 12:34, Julian Birch > wrote: > >> >> It gets better: they run a hoogle for the exact version, with every >> library. :) >> >> On Monday, March 2, 2015, emacstheviking > > wrote: >> >>> Took a while to sink in....DEF trying this out tonight >>> Looks AWESOME if it does what it says! >>> Getting excited about Haskell again. >>> THANKS!!!! Yoohoo :) >>> >>> >>> On 2 March 2015 at 12:10, Julian Birch wrote: >>> >>>> Just a small note: if you're suffering from cabal hell, LTS Haskell may >>>> help you. I described how to use it here: >>>> >>>> >>>> http://www.colourcoding.net/blog/archive/2015/02/22/hello-world-web-application-in-haskell.aspx >>>> >>>> Hope someone finds it useful. >>>> >>>> J >>>> >>>> >>>> On Monday, March 2, 2015, emacstheviking wrote: >>>> >>>>> Agreed. I will "finish" with a mild semi-demi-rant too regarding the >>>>> assumption by a lot of posters that we are all academics with access to >>>>> papers on this and that. I am not and I don't. If you cite a paper, make >>>>> sure it's available to Joe Public please! >>>>> >>>>> As for only sticking to plain vanialla simple Haskell, yes, that works >>>>> BUT there are some many great libraries that a real time savers...it's such >>>>> a shame when they won't play well together! >>>>> >>>>> So, despite it all, tonight I will be hacking Haskell ! >>>>> >>>>> :) >>>>> >>>>> >>>>> On 1 March 2015 at 19:27, DJ wrote: >>>>> >>>>>> Yeah. I think there are a lot of us out there. I won't rant (much) >>>>>> here, because I hope to get some help from time to time. Alienating people >>>>>> is not a good way to get help. >>>>>> >>>>>> But: >>>>>> >>>>>> There are many things I like about the language, but I have always >>>>>> been perplexed by the haskell ecosystem in a couple of ways. However good >>>>>> and/or interesting a language might be, it is not possible to do meat and >>>>>> potatoes development unless there is a good supply of packages/libraries. >>>>>> >>>>>> My first problem was that I often just could not get stuff to >>>>>> install. The second problem was documentation. I hope it has improved a >>>>>> bit. I was always flabbergasted at the (apparent) belief that a few lines >>>>>> of API documentation coughed out by haddock are enough. But that's all >>>>>> there was in a lot of cases. That, and "refer to xxxx research paper" and >>>>>> "figure it out from the types". Hah. Any math paper that consisted of just >>>>>> the equations sorted in alphabetical order would not be well received, I >>>>>> think. >>>>>> >>>>>> I really admired that fact that Michael Snoyman wrote a book about >>>>>> Yesod. For all I know he may not have kept the book up, but at least he >>>>>> realized that people needed an explanation of how to use his software. >>>>>> >>>>>> Well, back to work. I am going to give haskell another try for sure. >>>>>> It's just too tempting to give up on. If it doesn't work, the next stop >>>>>> will be sml or ocaml. >>>>>> >>>>>> Best, >>>>>> >>>>>> - DJ - >>>>>> >>>>>> >>>>>> On 15-03-01 09:56 AM, emacstheviking wrote: >>>>>> >>>>>> I feel your pain... >>>>>> >>>>>> >>>>>>> Confession: I abandoned Haskell two years ago because of frustration >>>>>>> with cabal and hackage. I decided to get back to the language today, and to >>>>>>> start with Haskell School of Expression. I immediately run into the problem >>>>>>> that the first thing I try to install with cabal does not work. >>>>>>> >>>>>>> It is the same reason I have stopped using it. It's a real shame. >>>>>> Those with better education and understanding than mine should be concerned >>>>>> that the uptake of the language is stunted by its package manager. >>>>>> >>>>>> I love Haskell. I have taught myself (the beginnings at least) of >>>>>> group theory just to better comprehend the mindset of monads. For that >>>>>> alone I am glad I learned Haskell as it has rekindled my interest in maths! >>>>>> >>>>>> >>>>>> >>>>>>> Thanks for any help. Please tell me things are not just as bad now >>>>>>> as they were when I left ;-) >>>>>>> >>>>>>> This mail seems to indicate to me that "cabal hell" is here for >>>>>> some time to come... >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> _______________________________________________ >>>>>> Beginners mailing listBeginners at haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>>>> >>>>>> >>>>>> >>>>>> _______________________________________________ >>>>>> Beginners mailing list >>>>>> Beginners at haskell.org >>>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>>>> >>>>>> >>>>> >>>> >>>> -- >>>> Sent from an iPhone, please excuse brevity and typos. >>>> >>>> _______________________________________________ >>>> Beginners mailing list >>>> Beginners at haskell.org >>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>> >>>> >>> >> >> -- >> Sent from an iPhone, please excuse brevity and typos. >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> > -- Sent from an iPhone, please excuse brevity and typos. -------------- next part -------------- An HTML attachment was scrubbed... URL: From sean at objitsu.com Mon Mar 2 13:04:34 2015 From: sean at objitsu.com (emacstheviking) Date: Mon, 2 Mar 2015 13:04:34 +0000 Subject: [Haskell-beginners] trying to install libraries for Haskell School of Expression In-Reply-To: References: <54F29851.9040202@arqux.com> <54F36837.5090704@arqux.com> Message-ID: Plunk! (penny drops) I get it...now that is truly the icing on the cabal-hell free cake! Thanks again Julian. On 2 March 2015 at 12:48, Julian Birch wrote: > If you go to www.stackage.com/lts/1.10, you'll find a hoogle search box. > It'll give you search results for everything in LTS 1.10. > > > On Monday, March 2, 2015, emacstheviking wrote: > >> What does that do for me within LTS confines? I know Hoogle, but I don't >> understand what you mean by "they run a hoogle for the exact version, >> with every library." ...I just want to understand so I can be as excited as >> everybody else right now! LOL :) >> >> >> On 2 March 2015 at 12:34, Julian Birch wrote: >> >>> >>> It gets better: they run a hoogle for the exact version, with every >>> library. :) >>> >>> On Monday, March 2, 2015, emacstheviking wrote: >>> >>>> Took a while to sink in....DEF trying this out tonight >>>> Looks AWESOME if it does what it says! >>>> Getting excited about Haskell again. >>>> THANKS!!!! Yoohoo :) >>>> >>>> >>>> On 2 March 2015 at 12:10, Julian Birch wrote: >>>> >>>>> Just a small note: if you're suffering from cabal hell, LTS Haskell >>>>> may help you. I described how to use it here: >>>>> >>>>> >>>>> http://www.colourcoding.net/blog/archive/2015/02/22/hello-world-web-application-in-haskell.aspx >>>>> >>>>> Hope someone finds it useful. >>>>> >>>>> J >>>>> >>>>> >>>>> On Monday, March 2, 2015, emacstheviking wrote: >>>>> >>>>>> Agreed. I will "finish" with a mild semi-demi-rant too regarding the >>>>>> assumption by a lot of posters that we are all academics with access to >>>>>> papers on this and that. I am not and I don't. If you cite a paper, make >>>>>> sure it's available to Joe Public please! >>>>>> >>>>>> As for only sticking to plain vanialla simple Haskell, yes, that >>>>>> works BUT there are some many great libraries that a real time >>>>>> savers...it's such a shame when they won't play well together! >>>>>> >>>>>> So, despite it all, tonight I will be hacking Haskell ! >>>>>> >>>>>> :) >>>>>> >>>>>> >>>>>> On 1 March 2015 at 19:27, DJ wrote: >>>>>> >>>>>>> Yeah. I think there are a lot of us out there. I won't rant (much) >>>>>>> here, because I hope to get some help from time to time. Alienating people >>>>>>> is not a good way to get help. >>>>>>> >>>>>>> But: >>>>>>> >>>>>>> There are many things I like about the language, but I have always >>>>>>> been perplexed by the haskell ecosystem in a couple of ways. However good >>>>>>> and/or interesting a language might be, it is not possible to do meat and >>>>>>> potatoes development unless there is a good supply of packages/libraries. >>>>>>> >>>>>>> My first problem was that I often just could not get stuff to >>>>>>> install. The second problem was documentation. I hope it has improved a >>>>>>> bit. I was always flabbergasted at the (apparent) belief that a few lines >>>>>>> of API documentation coughed out by haddock are enough. But that's all >>>>>>> there was in a lot of cases. That, and "refer to xxxx research paper" and >>>>>>> "figure it out from the types". Hah. Any math paper that consisted of just >>>>>>> the equations sorted in alphabetical order would not be well received, I >>>>>>> think. >>>>>>> >>>>>>> I really admired that fact that Michael Snoyman wrote a book about >>>>>>> Yesod. For all I know he may not have kept the book up, but at least he >>>>>>> realized that people needed an explanation of how to use his software. >>>>>>> >>>>>>> Well, back to work. I am going to give haskell another try for sure. >>>>>>> It's just too tempting to give up on. If it doesn't work, the next stop >>>>>>> will be sml or ocaml. >>>>>>> >>>>>>> Best, >>>>>>> >>>>>>> - DJ - >>>>>>> >>>>>>> >>>>>>> On 15-03-01 09:56 AM, emacstheviking wrote: >>>>>>> >>>>>>> I feel your pain... >>>>>>> >>>>>>> >>>>>>>> Confession: I abandoned Haskell two years ago because of >>>>>>>> frustration with cabal and hackage. I decided to get back to the language >>>>>>>> today, and to start with Haskell School of Expression. I immediately run >>>>>>>> into the problem that the first thing I try to install with cabal does not >>>>>>>> work. >>>>>>>> >>>>>>>> It is the same reason I have stopped using it. It's a real shame. >>>>>>> Those with better education and understanding than mine should be concerned >>>>>>> that the uptake of the language is stunted by its package manager. >>>>>>> >>>>>>> I love Haskell. I have taught myself (the beginnings at least) of >>>>>>> group theory just to better comprehend the mindset of monads. For that >>>>>>> alone I am glad I learned Haskell as it has rekindled my interest in maths! >>>>>>> >>>>>>> >>>>>>> >>>>>>>> Thanks for any help. Please tell me things are not just as bad now >>>>>>>> as they were when I left ;-) >>>>>>>> >>>>>>>> This mail seems to indicate to me that "cabal hell" is here for >>>>>>> some time to come... >>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> _______________________________________________ >>>>>>> Beginners mailing listBeginners at haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>>>>> >>>>>>> >>>>>>> >>>>>>> _______________________________________________ >>>>>>> Beginners mailing list >>>>>>> Beginners at haskell.org >>>>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>>>>> >>>>>>> >>>>>> >>>>> >>>>> -- >>>>> Sent from an iPhone, please excuse brevity and typos. >>>>> >>>>> _______________________________________________ >>>>> Beginners mailing list >>>>> Beginners at haskell.org >>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>>> >>>>> >>>> >>> >>> -- >>> Sent from an iPhone, please excuse brevity and typos. >>> >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >>> >> > > -- > Sent from an iPhone, please excuse brevity and typos. > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sean at objitsu.com Mon Mar 2 13:06:22 2015 From: sean at objitsu.com (emacstheviking) Date: Mon, 2 Mar 2015 13:06:22 +0000 Subject: [Haskell-beginners] trying to install libraries for Haskell School of Expression In-Reply-To: References: <54F29851.9040202@arqux.com> <54F36837.5090704@arqux.com> Message-ID: PS: Did you mean stackage .ORG not .COM On 2 March 2015 at 13:04, emacstheviking wrote: > Plunk! (penny drops) > I get it...now that is truly the icing on the cabal-hell free cake! > Thanks again Julian. > > > On 2 March 2015 at 12:48, Julian Birch wrote: > >> If you go to www.stackage.com/lts/1.10, you'll find a hoogle search box. >> It'll give you search results for everything in LTS 1.10. >> >> >> On Monday, March 2, 2015, emacstheviking wrote: >> >>> What does that do for me within LTS confines? I know Hoogle, but I don't >>> understand what you mean by "they run a hoogle for the exact version, >>> with every library." ...I just want to understand so I can be as excited as >>> everybody else right now! LOL :) >>> >>> >>> On 2 March 2015 at 12:34, Julian Birch wrote: >>> >>>> >>>> It gets better: they run a hoogle for the exact version, with every >>>> library. :) >>>> >>>> On Monday, March 2, 2015, emacstheviking wrote: >>>> >>>>> Took a while to sink in....DEF trying this out tonight >>>>> Looks AWESOME if it does what it says! >>>>> Getting excited about Haskell again. >>>>> THANKS!!!! Yoohoo :) >>>>> >>>>> >>>>> On 2 March 2015 at 12:10, Julian Birch wrote: >>>>> >>>>>> Just a small note: if you're suffering from cabal hell, LTS Haskell >>>>>> may help you. I described how to use it here: >>>>>> >>>>>> >>>>>> http://www.colourcoding.net/blog/archive/2015/02/22/hello-world-web-application-in-haskell.aspx >>>>>> >>>>>> Hope someone finds it useful. >>>>>> >>>>>> J >>>>>> >>>>>> >>>>>> On Monday, March 2, 2015, emacstheviking wrote: >>>>>> >>>>>>> Agreed. I will "finish" with a mild semi-demi-rant too regarding the >>>>>>> assumption by a lot of posters that we are all academics with access to >>>>>>> papers on this and that. I am not and I don't. If you cite a paper, make >>>>>>> sure it's available to Joe Public please! >>>>>>> >>>>>>> As for only sticking to plain vanialla simple Haskell, yes, that >>>>>>> works BUT there are some many great libraries that a real time >>>>>>> savers...it's such a shame when they won't play well together! >>>>>>> >>>>>>> So, despite it all, tonight I will be hacking Haskell ! >>>>>>> >>>>>>> :) >>>>>>> >>>>>>> >>>>>>> On 1 March 2015 at 19:27, DJ wrote: >>>>>>> >>>>>>>> Yeah. I think there are a lot of us out there. I won't rant (much) >>>>>>>> here, because I hope to get some help from time to time. Alienating people >>>>>>>> is not a good way to get help. >>>>>>>> >>>>>>>> But: >>>>>>>> >>>>>>>> There are many things I like about the language, but I have always >>>>>>>> been perplexed by the haskell ecosystem in a couple of ways. However good >>>>>>>> and/or interesting a language might be, it is not possible to do meat and >>>>>>>> potatoes development unless there is a good supply of packages/libraries. >>>>>>>> >>>>>>>> My first problem was that I often just could not get stuff to >>>>>>>> install. The second problem was documentation. I hope it has improved a >>>>>>>> bit. I was always flabbergasted at the (apparent) belief that a few lines >>>>>>>> of API documentation coughed out by haddock are enough. But that's all >>>>>>>> there was in a lot of cases. That, and "refer to xxxx research paper" and >>>>>>>> "figure it out from the types". Hah. Any math paper that consisted of just >>>>>>>> the equations sorted in alphabetical order would not be well received, I >>>>>>>> think. >>>>>>>> >>>>>>>> I really admired that fact that Michael Snoyman wrote a book about >>>>>>>> Yesod. For all I know he may not have kept the book up, but at least he >>>>>>>> realized that people needed an explanation of how to use his software. >>>>>>>> >>>>>>>> Well, back to work. I am going to give haskell another try for >>>>>>>> sure. It's just too tempting to give up on. If it doesn't work, the next >>>>>>>> stop will be sml or ocaml. >>>>>>>> >>>>>>>> Best, >>>>>>>> >>>>>>>> - DJ - >>>>>>>> >>>>>>>> >>>>>>>> On 15-03-01 09:56 AM, emacstheviking wrote: >>>>>>>> >>>>>>>> I feel your pain... >>>>>>>> >>>>>>>> >>>>>>>>> Confession: I abandoned Haskell two years ago because of >>>>>>>>> frustration with cabal and hackage. I decided to get back to the language >>>>>>>>> today, and to start with Haskell School of Expression. I immediately run >>>>>>>>> into the problem that the first thing I try to install with cabal does not >>>>>>>>> work. >>>>>>>>> >>>>>>>>> It is the same reason I have stopped using it. It's a real >>>>>>>> shame. Those with better education and understanding than mine should be >>>>>>>> concerned that the uptake of the language is stunted by its package manager. >>>>>>>> >>>>>>>> I love Haskell. I have taught myself (the beginnings at least) of >>>>>>>> group theory just to better comprehend the mindset of monads. For that >>>>>>>> alone I am glad I learned Haskell as it has rekindled my interest in maths! >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>>> Thanks for any help. Please tell me things are not just as bad now >>>>>>>>> as they were when I left ;-) >>>>>>>>> >>>>>>>>> This mail seems to indicate to me that "cabal hell" is here for >>>>>>>> some time to come... >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> _______________________________________________ >>>>>>>> Beginners mailing listBeginners at haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> _______________________________________________ >>>>>>>> Beginners mailing list >>>>>>>> Beginners at haskell.org >>>>>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>>>>>> >>>>>>>> >>>>>>> >>>>>> >>>>>> -- >>>>>> Sent from an iPhone, please excuse brevity and typos. >>>>>> >>>>>> _______________________________________________ >>>>>> Beginners mailing list >>>>>> Beginners at haskell.org >>>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>>>> >>>>>> >>>>> >>>> >>>> -- >>>> Sent from an iPhone, please excuse brevity and typos. >>>> >>>> _______________________________________________ >>>> Beginners mailing list >>>> Beginners at haskell.org >>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>> >>>> >>> >> >> -- >> Sent from an iPhone, please excuse brevity and typos. >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From julian.birch at gmail.com Mon Mar 2 13:08:58 2015 From: julian.birch at gmail.com (Julian Birch) Date: Mon, 2 Mar 2015 13:08:58 +0000 Subject: [Haskell-beginners] trying to install libraries for Haskell School of Expression In-Reply-To: References: <54F29851.9040202@arqux.com> <54F36837.5090704@arqux.com> Message-ID: Yes, sorry, the perils of typing URLs out on your phone... :) On Monday, March 2, 2015, emacstheviking wrote: > PS: Did you mean stackage .ORG not .COM > > > On 2 March 2015 at 13:04, emacstheviking > wrote: > >> Plunk! (penny drops) >> I get it...now that is truly the icing on the cabal-hell free cake! >> Thanks again Julian. >> >> >> On 2 March 2015 at 12:48, Julian Birch > > wrote: >> >>> If you go to www.stackage.com/lts/1.10, you'll find a hoogle search box. >>> It'll give you search results for everything in LTS 1.10. >>> >>> >>> On Monday, March 2, 2015, emacstheviking >> > wrote: >>> >>>> What does that do for me within LTS confines? I know Hoogle, but I >>>> don't understand what you mean by "they run a hoogle for the exact >>>> version, with every library." ...I just want to understand so I can be as >>>> excited as everybody else right now! LOL :) >>>> >>>> >>>> On 2 March 2015 at 12:34, Julian Birch wrote: >>>> >>>>> >>>>> It gets better: they run a hoogle for the exact version, with every >>>>> library. :) >>>>> >>>>> On Monday, March 2, 2015, emacstheviking wrote: >>>>> >>>>>> Took a while to sink in....DEF trying this out tonight >>>>>> Looks AWESOME if it does what it says! >>>>>> Getting excited about Haskell again. >>>>>> THANKS!!!! Yoohoo :) >>>>>> >>>>>> >>>>>> On 2 March 2015 at 12:10, Julian Birch >>>>>> wrote: >>>>>> >>>>>>> Just a small note: if you're suffering from cabal hell, LTS Haskell >>>>>>> may help you. I described how to use it here: >>>>>>> >>>>>>> >>>>>>> http://www.colourcoding.net/blog/archive/2015/02/22/hello-world-web-application-in-haskell.aspx >>>>>>> >>>>>>> Hope someone finds it useful. >>>>>>> >>>>>>> J >>>>>>> >>>>>>> >>>>>>> On Monday, March 2, 2015, emacstheviking wrote: >>>>>>> >>>>>>>> Agreed. I will "finish" with a mild semi-demi-rant too regarding >>>>>>>> the assumption by a lot of posters that we are all academics with access to >>>>>>>> papers on this and that. I am not and I don't. If you cite a paper, make >>>>>>>> sure it's available to Joe Public please! >>>>>>>> >>>>>>>> As for only sticking to plain vanialla simple Haskell, yes, that >>>>>>>> works BUT there are some many great libraries that a real time >>>>>>>> savers...it's such a shame when they won't play well together! >>>>>>>> >>>>>>>> So, despite it all, tonight I will be hacking Haskell ! >>>>>>>> >>>>>>>> :) >>>>>>>> >>>>>>>> >>>>>>>> On 1 March 2015 at 19:27, DJ wrote: >>>>>>>> >>>>>>>>> Yeah. I think there are a lot of us out there. I won't rant >>>>>>>>> (much) here, because I hope to get some help from time to time. Alienating >>>>>>>>> people is not a good way to get help. >>>>>>>>> >>>>>>>>> But: >>>>>>>>> >>>>>>>>> There are many things I like about the language, but I have always >>>>>>>>> been perplexed by the haskell ecosystem in a couple of ways. However good >>>>>>>>> and/or interesting a language might be, it is not possible to do meat and >>>>>>>>> potatoes development unless there is a good supply of packages/libraries. >>>>>>>>> >>>>>>>>> My first problem was that I often just could not get stuff to >>>>>>>>> install. The second problem was documentation. I hope it has improved a >>>>>>>>> bit. I was always flabbergasted at the (apparent) belief that a few lines >>>>>>>>> of API documentation coughed out by haddock are enough. But that's all >>>>>>>>> there was in a lot of cases. That, and "refer to xxxx research paper" and >>>>>>>>> "figure it out from the types". Hah. Any math paper that consisted of just >>>>>>>>> the equations sorted in alphabetical order would not be well received, I >>>>>>>>> think. >>>>>>>>> >>>>>>>>> I really admired that fact that Michael Snoyman wrote a book about >>>>>>>>> Yesod. For all I know he may not have kept the book up, but at least he >>>>>>>>> realized that people needed an explanation of how to use his software. >>>>>>>>> >>>>>>>>> Well, back to work. I am going to give haskell another try for >>>>>>>>> sure. It's just too tempting to give up on. If it doesn't work, the next >>>>>>>>> stop will be sml or ocaml. >>>>>>>>> >>>>>>>>> Best, >>>>>>>>> >>>>>>>>> - DJ - >>>>>>>>> >>>>>>>>> >>>>>>>>> On 15-03-01 09:56 AM, emacstheviking wrote: >>>>>>>>> >>>>>>>>> I feel your pain... >>>>>>>>> >>>>>>>>> >>>>>>>>>> Confession: I abandoned Haskell two years ago because of >>>>>>>>>> frustration with cabal and hackage. I decided to get back to the language >>>>>>>>>> today, and to start with Haskell School of Expression. I immediately run >>>>>>>>>> into the problem that the first thing I try to install with cabal does not >>>>>>>>>> work. >>>>>>>>>> >>>>>>>>>> It is the same reason I have stopped using it. It's a real >>>>>>>>> shame. Those with better education and understanding than mine should be >>>>>>>>> concerned that the uptake of the language is stunted by its package manager. >>>>>>>>> >>>>>>>>> I love Haskell. I have taught myself (the beginnings at least) >>>>>>>>> of group theory just to better comprehend the mindset of monads. For that >>>>>>>>> alone I am glad I learned Haskell as it has rekindled my interest in maths! >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>>> Thanks for any help. Please tell me things are not just as bad >>>>>>>>>> now as they were when I left ;-) >>>>>>>>>> >>>>>>>>>> This mail seems to indicate to me that "cabal hell" is here for >>>>>>>>> some time to come... >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> _______________________________________________ >>>>>>>>> Beginners mailing listBeginners at haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> _______________________________________________ >>>>>>>>> Beginners mailing list >>>>>>>>> Beginners at haskell.org >>>>>>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>>>>>>> >>>>>>>>> >>>>>>>> >>>>>>> >>>>>>> -- >>>>>>> Sent from an iPhone, please excuse brevity and typos. >>>>>>> >>>>>>> _______________________________________________ >>>>>>> Beginners mailing list >>>>>>> Beginners at haskell.org >>>>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>>>>> >>>>>>> >>>>>> >>>>> >>>>> -- >>>>> Sent from an iPhone, please excuse brevity and typos. >>>>> >>>>> _______________________________________________ >>>>> Beginners mailing list >>>>> Beginners at haskell.org >>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>>> >>>>> >>>> >>> >>> -- >>> Sent from an iPhone, please excuse brevity and typos. >>> >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >>> >> > -- Sent from an iPhone, please excuse brevity and typos. -------------- next part -------------- An HTML attachment was scrubbed... URL: From objitsu at gmail.com Mon Mar 2 13:12:41 2015 From: objitsu at gmail.com (emacstheviking) Date: Mon, 2 Mar 2015 13:12:41 +0000 Subject: [Haskell-beginners] trying to install libraries for Haskell School of Expression In-Reply-To: References: <54F29851.9040202@arqux.com> <54F36837.5090704@arqux.com> Message-ID: Coupled with auto-correction that you don't see until after you send... On 2 March 2015 at 13:08, Julian Birch wrote: > Yes, sorry, the perils of typing URLs out on your phone... :) > > > On Monday, March 2, 2015, emacstheviking wrote: > >> PS: Did you mean stackage .ORG not .COM >> >> >> On 2 March 2015 at 13:04, emacstheviking wrote: >> >>> Plunk! (penny drops) >>> I get it...now that is truly the icing on the cabal-hell free cake! >>> Thanks again Julian. >>> >>> >>> On 2 March 2015 at 12:48, Julian Birch wrote: >>> >>>> If you go to www.stackage.com/lts/1.10, you'll find a hoogle search box. >>>> It'll give you search results for everything in LTS 1.10. >>>> >>>> >>>> On Monday, March 2, 2015, emacstheviking wrote: >>>> >>>>> What does that do for me within LTS confines? I know Hoogle, but I >>>>> don't understand what you mean by "they run a hoogle for the exact >>>>> version, with every library." ...I just want to understand so I can be as >>>>> excited as everybody else right now! LOL :) >>>>> >>>>> >>>>> On 2 March 2015 at 12:34, Julian Birch wrote: >>>>> >>>>>> >>>>>> It gets better: they run a hoogle for the exact version, with every >>>>>> library. :) >>>>>> >>>>>> On Monday, March 2, 2015, emacstheviking wrote: >>>>>> >>>>>>> Took a while to sink in....DEF trying this out tonight >>>>>>> Looks AWESOME if it does what it says! >>>>>>> Getting excited about Haskell again. >>>>>>> THANKS!!!! Yoohoo :) >>>>>>> >>>>>>> >>>>>>> On 2 March 2015 at 12:10, Julian Birch >>>>>>> wrote: >>>>>>> >>>>>>>> Just a small note: if you're suffering from cabal hell, LTS Haskell >>>>>>>> may help you. I described how to use it here: >>>>>>>> >>>>>>>> >>>>>>>> http://www.colourcoding.net/blog/archive/2015/02/22/hello-world-web-application-in-haskell.aspx >>>>>>>> >>>>>>>> Hope someone finds it useful. >>>>>>>> >>>>>>>> J >>>>>>>> >>>>>>>> >>>>>>>> On Monday, March 2, 2015, emacstheviking wrote: >>>>>>>> >>>>>>>>> Agreed. I will "finish" with a mild semi-demi-rant too regarding >>>>>>>>> the assumption by a lot of posters that we are all academics with access to >>>>>>>>> papers on this and that. I am not and I don't. If you cite a paper, make >>>>>>>>> sure it's available to Joe Public please! >>>>>>>>> >>>>>>>>> As for only sticking to plain vanialla simple Haskell, yes, that >>>>>>>>> works BUT there are some many great libraries that a real time >>>>>>>>> savers...it's such a shame when they won't play well together! >>>>>>>>> >>>>>>>>> So, despite it all, tonight I will be hacking Haskell ! >>>>>>>>> >>>>>>>>> :) >>>>>>>>> >>>>>>>>> >>>>>>>>> On 1 March 2015 at 19:27, DJ wrote: >>>>>>>>> >>>>>>>>>> Yeah. I think there are a lot of us out there. I won't rant >>>>>>>>>> (much) here, because I hope to get some help from time to time. Alienating >>>>>>>>>> people is not a good way to get help. >>>>>>>>>> >>>>>>>>>> But: >>>>>>>>>> >>>>>>>>>> There are many things I like about the language, but I have >>>>>>>>>> always been perplexed by the haskell ecosystem in a couple of ways. However >>>>>>>>>> good and/or interesting a language might be, it is not possible to do meat >>>>>>>>>> and potatoes development unless there is a good supply of >>>>>>>>>> packages/libraries. >>>>>>>>>> >>>>>>>>>> My first problem was that I often just could not get stuff to >>>>>>>>>> install. The second problem was documentation. I hope it has improved a >>>>>>>>>> bit. I was always flabbergasted at the (apparent) belief that a few lines >>>>>>>>>> of API documentation coughed out by haddock are enough. But that's all >>>>>>>>>> there was in a lot of cases. That, and "refer to xxxx research paper" and >>>>>>>>>> "figure it out from the types". Hah. Any math paper that consisted of just >>>>>>>>>> the equations sorted in alphabetical order would not be well received, I >>>>>>>>>> think. >>>>>>>>>> >>>>>>>>>> I really admired that fact that Michael Snoyman wrote a book >>>>>>>>>> about Yesod. For all I know he may not have kept the book up, but at least >>>>>>>>>> he realized that people needed an explanation of how to use his software. >>>>>>>>>> >>>>>>>>>> Well, back to work. I am going to give haskell another try for >>>>>>>>>> sure. It's just too tempting to give up on. If it doesn't work, the next >>>>>>>>>> stop will be sml or ocaml. >>>>>>>>>> >>>>>>>>>> Best, >>>>>>>>>> >>>>>>>>>> - DJ - >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> On 15-03-01 09:56 AM, emacstheviking wrote: >>>>>>>>>> >>>>>>>>>> I feel your pain... >>>>>>>>>> >>>>>>>>>> >>>>>>>>>>> Confession: I abandoned Haskell two years ago because of >>>>>>>>>>> frustration with cabal and hackage. I decided to get back to the language >>>>>>>>>>> today, and to start with Haskell School of Expression. I immediately run >>>>>>>>>>> into the problem that the first thing I try to install with cabal does not >>>>>>>>>>> work. >>>>>>>>>>> >>>>>>>>>>> It is the same reason I have stopped using it. It's a real >>>>>>>>>> shame. Those with better education and understanding than mine should be >>>>>>>>>> concerned that the uptake of the language is stunted by its package manager. >>>>>>>>>> >>>>>>>>>> I love Haskell. I have taught myself (the beginnings at least) >>>>>>>>>> of group theory just to better comprehend the mindset of monads. For that >>>>>>>>>> alone I am glad I learned Haskell as it has rekindled my interest in maths! >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>>> Thanks for any help. Please tell me things are not just as bad >>>>>>>>>>> now as they were when I left ;-) >>>>>>>>>>> >>>>>>>>>>> This mail seems to indicate to me that "cabal hell" is here >>>>>>>>>> for some time to come... >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> _______________________________________________ >>>>>>>>>> Beginners mailing listBeginners at haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> _______________________________________________ >>>>>>>>>> Beginners mailing list >>>>>>>>>> Beginners at haskell.org >>>>>>>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>>>>>>>> >>>>>>>>>> >>>>>>>>> >>>>>>>> >>>>>>>> -- >>>>>>>> Sent from an iPhone, please excuse brevity and typos. >>>>>>>> >>>>>>>> _______________________________________________ >>>>>>>> Beginners mailing list >>>>>>>> Beginners at haskell.org >>>>>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>>>>>> >>>>>>>> >>>>>>> >>>>>> >>>>>> -- >>>>>> Sent from an iPhone, please excuse brevity and typos. >>>>>> >>>>>> _______________________________________________ >>>>>> Beginners mailing list >>>>>> Beginners at haskell.org >>>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>>>> >>>>>> >>>>> >>>> >>>> -- >>>> Sent from an iPhone, please excuse brevity and typos. >>>> >>>> _______________________________________________ >>>> Beginners mailing list >>>> Beginners at haskell.org >>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>> >>>> >>> >> > > -- > Sent from an iPhone, please excuse brevity and typos. > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From hsyl20 at gmail.com Mon Mar 2 15:20:00 2015 From: hsyl20 at gmail.com (Sylvain Henry) Date: Mon, 2 Mar 2015 16:20:00 +0100 Subject: [Haskell-beginners] FFI Problems In-Reply-To: <54F1C085.7020503@nyu.edu> References: <54F1C085.7020503@nyu.edu> Message-ID: Hi, 1) You have a copy-paste error on the following line (s/bitrate/track) track <- ((#peek struct music_metadata, bitrate) a) :: IO Int 2) By looking at the values you get in hexadecimal, you are reading 64bits values when your C struct contains 32 bits values. If you use: peek ... :: IO Int32, it should be ok. 3) From a style point of view, you could use Applicative operators (from Control.Applicative) to avoid temporary names: peek a = MusicMetaData <$> liftM constantToCodec $ (((#peek struct music_metadata, codec) a) :: IO Int32) <*> fmap fromIntegral (((#peek struct music_metadata, length) a) :: IO Int32) <*> fmap fromIntegral (((#peek struct music_metadata, bitrate) a) :: IO Int32) <*> fmap fromIntegral (((#peek struct music_metadata, channels) a) :: IO Int32) <*> fmap fromIntegral (((#peek struct music_metadata, track) a) :: IO Int32) <*> (peekCString =<< (#peek struct music_metadata, title) a) ... 4) In your constantToCodec function, you don't need the temporary names for all the constants. Best regards, Sylvain PS : recently I have been working on rewriting the FFI page on the wiki to make it more beginner-friendly ;-). It is not totally finished but I'm open to any comment. https://www.haskell.org/wiki/Foreign_Function_Interface 2015-02-28 14:20 GMT+01:00 Thomas Jakway : > I'm very new to Haskell and am trying to write a "real" program to > motivate myself to learn it better (so far I've only gotten through Project > Euler problems after reading LYAH and most of RWH). I'm using Taglib ( > https://github.com/taglib/taglib) to read the metadata from a music file > and print it. I have a struct C-side (with C linkage) serving as the > bridge between Taglib's C++ and Haskell's FFI. A small demo program > (compiled with gcc and linked against the C++ object files) gives the > correct results, but Haskell is weirdly only getting *some *of it right. > Specifically, the C string fields are working but ints are not. > > The output from the C demo (what Haskell should be printing): > > music_metadata > title: It's My Life, artist: Bon Jovi, album: Bon Jovi Greatest Hits > - The Ultimate Collection > comment: , genre: Rock, track: 3, > length: 224, bitrate: 256, channels: 2, > codec: 768 > > The output from Haskell: > > MusicMetadata {codec = UNKNOWN, length = 1099511628000, bitrate = > 8589934848, channels = 12884901890, track = 8589934848, title = "It's My > Life", artist = "Bon Jovi", album = "Bon Jovi Greatest Hits - The Ultimate > Collection", comment = "", genre = "Rock"} > > I would have expected it to work or not work at all, but did not > anticipate getting only some of it right. > > I was going to include snippets from my hsc file but given how new I am to > Haskell I don't trust myself to assume where the problem is, so sorry if > this is way too long: > > {-# LANGUAGE CPP, ForeignFunctionInterface #-} > > module MusicReader > ( Codec, > MusicMetadata, > readMusicMetadata > ) where > > import Control.Monad > import Foreign > import Foreign.C.Types > import Foreign.C.String > import System.IO.Unsafe as Unsafe > > #include "CodecDefines.h" > #include "MusicReader.h" > > constantToCodec code > | code == mp3 = MP3 > | code == flac = FLAC > | code == ogg = OGG_VORBIS > | code == mp4 = MP4 > | code == mpeg = MPEG > | code == none = NONE > | code == unknown = UNKNOWN > | otherwise = UNKNOWN > where mp3 = #const MP3_CODEC > flac = #const FLAC_CODEC > ogg = #const OGG_VORBIS_CODEC > mp4 = #const MP4_CODEC > mpeg = #const MPEG_CODEC > none = #const NO_EXTENSION > unknown = #const UNKNOWN_EXTENSION > > data Codec = MP3 | FLAC | OGG_VORBIS | MP4 | MPEG | NONE | UNKNOWN > deriving (Show) > > data MusicMetadata = MusicMetadata { codec :: Codec, > length :: Int, > bitrate :: Int, > channels :: Int, > track :: Int, > title :: String, > artist :: String, > album :: String, > comment :: String, > genre :: String } deriving (Show) > > instance Storable MusicMetadata where > sizeOf _ = (#size struct music_metadata) > alignment _ = alignment (undefined::CDouble) > peek a = do > codec <- liftM constantToCodec $ (((#peek struct music_metadata, > codec) a) :: IO Int) > length <- ((#peek struct music_metadata, length) a) :: IO Int > bitrate <- ((#peek struct music_metadata, bitrate) a) :: IO Int > channels <- ((#peek struct music_metadata, channels) a) :: IO Int > track <- ((#peek struct music_metadata, bitrate) a) :: IO Int > title <- ((#peek struct music_metadata, title) a) :: IO CString > artist <- ((#peek struct music_metadata, artist) a) :: IO CString > album <- ((#peek struct music_metadata, album) a) :: IO CString > comment <- ((#peek struct music_metadata, comment) a) :: IO CString > genre <- ((#peek struct music_metadata, genre) a) :: IO CString > --FIXME: find replacement for temporary names > marshalledTitle <- peekCString title > marshalledArtist <- peekCString artist > marshalledAlbum <- peekCString album > marshalledComment <- peekCString comment > marshalledGenre <- peekCString genre > return (MusicMetadata codec length bitrate channels track > marshalledTitle marshalledArtist marshalledAlbum marshalledComment > marshalledGenre) > poke a = undefined > > --This is the "primitive" FFI call--calls the C function and gets a pointer > --in return > --TODO: write a higher level function this module should export that calls > --primReadMusicMetadata and converts the C Pointer into the Haskell data > --MusicMetadata > foreign import ccall unsafe "read_metadata" primReadMusicMetadata :: > CString -> IO (Ptr MusicMetadata) > > --convert the Haskell string to a CString, call into the FFI then > --dereference the resulting pointer > readMusicMetadata a = join $ withCString a $ \cs -> ((liftM peek) $ > primReadMusicMetadata cs) > > > > Here's the struct in MusicReader.h (in an extern C block): > struct music_metadata > { > int codec; > int length, > bitrate, > channels; > int track; > char *title, > *artist, > *album, > *comment, > *genre; > }; > > > with the corresponding call: > struct music_metadata* read_metadata(char*); > > > I've tried playing around with the alignment but it didn't do anything. I > also tried declaring the struct's fields as int32_t which also did nothing. > > The C demo in question is a very simple: > > #include > #include "MusicReader.h" > > #define FILENAME "Its_My_Life.m4a" > > int main() > { > struct music_metadata* metadata = read_metadata(FILENAME); > printf("music_metadata\ntitle: %s,\tartist: %s,\talbum: %s\n", > metadata->title, metadata->artist, metadata->album); > printf("comment: %s,\tgenre: %s,\ttrack: %d,\n", > metadata->comment, metadata->genre, metadata->track); > printf("length: %d,\tbitrate: %d,\tchannels: %d,\n", > metadata->length, metadata->bitrate, metadata->channels); > printf("codec: %d\n"); > > } > > It just reads the metadata into the struct and prints the fields. > > I've gotten the impression of the Haskell FFI being very > beginner-unfriendly, which isn't surprising but still disappointing because > it would be a great opportunity to replace some projects with Haskell. > > Any help is appreciated, including general feedback on my code! > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From hsyl20 at gmail.com Mon Mar 2 15:30:27 2015 From: hsyl20 at gmail.com (Sylvain Henry) Date: Mon, 2 Mar 2015 16:30:27 +0100 Subject: [Haskell-beginners] FFI Problems In-Reply-To: References: <54F1C085.7020503@nyu.edu> Message-ID: I forgot to comment this line from your code: readMusicMetadata a = join $ withCString a $ \cs -> ((liftM peek) $ primReadMusicMetadata cs) I would write: readMusicMetadata a = withCString a $ \cs -> do p <- primReadMusicMetadata cs peek p Or: readMusicMetadata a = withCString a $ \cs -> (peek =<< primReadMusicMetadata cs) Or (with (<=<) from Control.Monad): readMusicMetadata a = withCString a (peek <=< primReadMusicMetadata) Best regards, Sylvain 2015-03-02 16:20 GMT+01:00 Sylvain Henry : > Hi, > > 1) You have a copy-paste error on the following line (s/bitrate/track) > track <- ((#peek struct music_metadata, bitrate) a) :: IO Int > > 2) By looking at the values you get in hexadecimal, you are reading 64bits > values when your C struct contains 32 bits values. If you use: peek ... :: > IO Int32, it should be ok. > > 3) From a style point of view, you could use Applicative operators (from > Control.Applicative) to avoid temporary names: > peek a = MusicMetaData > <$> liftM constantToCodec $ (((#peek struct music_metadata, codec) > a) :: IO Int32) > <*> fmap fromIntegral (((#peek struct music_metadata, length) a) > :: IO Int32) > <*> fmap fromIntegral (((#peek struct music_metadata, bitrate) a) > :: IO Int32) > <*> fmap fromIntegral (((#peek struct music_metadata, channels) a) > :: IO Int32) > <*> fmap fromIntegral (((#peek struct music_metadata, track) a) :: > IO Int32) > <*> (peekCString =<< (#peek struct music_metadata, title) a) > ... > > 4) In your constantToCodec function, you don't need the temporary names > for all the constants. > > Best regards, > Sylvain > > PS : recently I have been working on rewriting the FFI page on the wiki to > make it more beginner-friendly ;-). It is not totally finished but I'm open > to any comment. https://www.haskell.org/wiki/Foreign_Function_Interface > > 2015-02-28 14:20 GMT+01:00 Thomas Jakway : > >> I'm very new to Haskell and am trying to write a "real" program to >> motivate myself to learn it better (so far I've only gotten through Project >> Euler problems after reading LYAH and most of RWH). I'm using Taglib ( >> https://github.com/taglib/taglib) to read the metadata from a music file >> and print it. I have a struct C-side (with C linkage) serving as the >> bridge between Taglib's C++ and Haskell's FFI. A small demo program >> (compiled with gcc and linked against the C++ object files) gives the >> correct results, but Haskell is weirdly only getting *some *of it >> right. Specifically, the C string fields are working but ints are not. >> >> The output from the C demo (what Haskell should be printing): >> >> music_metadata >> title: It's My Life, artist: Bon Jovi, album: Bon Jovi Greatest >> Hits - The Ultimate Collection >> comment: , genre: Rock, track: 3, >> length: 224, bitrate: 256, channels: 2, >> codec: 768 >> >> The output from Haskell: >> >> MusicMetadata {codec = UNKNOWN, length = 1099511628000, bitrate = >> 8589934848, channels = 12884901890, track = 8589934848, title = "It's My >> Life", artist = "Bon Jovi", album = "Bon Jovi Greatest Hits - The Ultimate >> Collection", comment = "", genre = "Rock"} >> >> I would have expected it to work or not work at all, but did not >> anticipate getting only some of it right. >> >> I was going to include snippets from my hsc file but given how new I am >> to Haskell I don't trust myself to assume where the problem is, so sorry if >> this is way too long: >> >> {-# LANGUAGE CPP, ForeignFunctionInterface #-} >> >> module MusicReader >> ( Codec, >> MusicMetadata, >> readMusicMetadata >> ) where >> >> import Control.Monad >> import Foreign >> import Foreign.C.Types >> import Foreign.C.String >> import System.IO.Unsafe as Unsafe >> >> #include "CodecDefines.h" >> #include "MusicReader.h" >> >> constantToCodec code >> | code == mp3 = MP3 >> | code == flac = FLAC >> | code == ogg = OGG_VORBIS >> | code == mp4 = MP4 >> | code == mpeg = MPEG >> | code == none = NONE >> | code == unknown = UNKNOWN >> | otherwise = UNKNOWN >> where mp3 = #const MP3_CODEC >> flac = #const FLAC_CODEC >> ogg = #const OGG_VORBIS_CODEC >> mp4 = #const MP4_CODEC >> mpeg = #const MPEG_CODEC >> none = #const NO_EXTENSION >> unknown = #const UNKNOWN_EXTENSION >> >> data Codec = MP3 | FLAC | OGG_VORBIS | MP4 | MPEG | NONE | UNKNOWN >> deriving (Show) >> >> data MusicMetadata = MusicMetadata { codec :: Codec, >> length :: Int, >> bitrate :: Int, >> channels :: Int, >> track :: Int, >> title :: String, >> artist :: String, >> album :: String, >> comment :: String, >> genre :: String } deriving (Show) >> >> instance Storable MusicMetadata where >> sizeOf _ = (#size struct music_metadata) >> alignment _ = alignment (undefined::CDouble) >> peek a = do >> codec <- liftM constantToCodec $ (((#peek struct music_metadata, >> codec) a) :: IO Int) >> length <- ((#peek struct music_metadata, length) a) :: IO Int >> bitrate <- ((#peek struct music_metadata, bitrate) a) :: IO Int >> channels <- ((#peek struct music_metadata, channels) a) :: IO Int >> track <- ((#peek struct music_metadata, bitrate) a) :: IO Int >> title <- ((#peek struct music_metadata, title) a) :: IO CString >> artist <- ((#peek struct music_metadata, artist) a) :: IO CString >> album <- ((#peek struct music_metadata, album) a) :: IO CString >> comment <- ((#peek struct music_metadata, comment) a) :: IO >> CString >> genre <- ((#peek struct music_metadata, genre) a) :: IO CString >> --FIXME: find replacement for temporary names >> marshalledTitle <- peekCString title >> marshalledArtist <- peekCString artist >> marshalledAlbum <- peekCString album >> marshalledComment <- peekCString comment >> marshalledGenre <- peekCString genre >> return (MusicMetadata codec length bitrate channels track >> marshalledTitle marshalledArtist marshalledAlbum marshalledComment >> marshalledGenre) >> poke a = undefined >> >> --This is the "primitive" FFI call--calls the C function and gets a >> pointer >> --in return >> --TODO: write a higher level function this module should export that calls >> --primReadMusicMetadata and converts the C Pointer into the Haskell data >> --MusicMetadata >> foreign import ccall unsafe "read_metadata" primReadMusicMetadata :: >> CString -> IO (Ptr MusicMetadata) >> >> --convert the Haskell string to a CString, call into the FFI then >> --dereference the resulting pointer >> readMusicMetadata a = join $ withCString a $ \cs -> ((liftM peek) $ >> primReadMusicMetadata cs) >> >> >> >> Here's the struct in MusicReader.h (in an extern C block): >> struct music_metadata >> { >> int codec; >> int length, >> bitrate, >> channels; >> int track; >> char *title, >> *artist, >> *album, >> *comment, >> *genre; >> }; >> >> >> with the corresponding call: >> struct music_metadata* read_metadata(char*); >> >> >> I've tried playing around with the alignment but it didn't do anything. >> I also tried declaring the struct's fields as int32_t which also did >> nothing. >> >> The C demo in question is a very simple: >> >> #include >> #include "MusicReader.h" >> >> #define FILENAME "Its_My_Life.m4a" >> >> int main() >> { >> struct music_metadata* metadata = read_metadata(FILENAME); >> printf("music_metadata\ntitle: %s,\tartist: %s,\talbum: %s\n", >> metadata->title, metadata->artist, metadata->album); >> printf("comment: %s,\tgenre: %s,\ttrack: %d,\n", >> metadata->comment, metadata->genre, metadata->track); >> printf("length: %d,\tbitrate: %d,\tchannels: %d,\n", >> metadata->length, metadata->bitrate, metadata->channels); >> printf("codec: %d\n"); >> >> } >> >> It just reads the metadata into the struct and prints the fields. >> >> I've gotten the impression of the Haskell FFI being very >> beginner-unfriendly, which isn't surprising but still disappointing because >> it would be a great opportunity to replace some projects with Haskell. >> >> Any help is appreciated, including general feedback on my code! >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sumit.sahrawat.apm13 at iitbhu.ac.in Mon Mar 2 20:43:15 2015 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Tue, 3 Mar 2015 02:13:15 +0530 Subject: [Haskell-beginners] CodeWarriors -- Spreading the word Message-ID: I just found out about www.codewarriors.com, and wanted to spread the word. It's a good place for beginners to get questions in increasing order of complexity. Best. -- Regards Sumit Sahrawat -------------- next part -------------- An HTML attachment was scrubbed... URL: From sumit.sahrawat.apm13 at iitbhu.ac.in Mon Mar 2 20:44:07 2015 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Tue, 3 Mar 2015 02:14:07 +0530 Subject: [Haskell-beginners] CodeWarriors -- Spreading the word In-Reply-To: References: Message-ID: Sorry, I meant www.codewars.com. On 3 March 2015 at 02:13, Sumit Sahrawat, Maths & Computing, IIT (BHU) < sumit.sahrawat.apm13 at iitbhu.ac.in> wrote: > I just found out about www.codewarriors.com, and wanted to spread the > word. > It's a good place for beginners to get questions in increasing order of > complexity. > > Best. > > -- > Regards > > Sumit Sahrawat > -- Regards Sumit Sahrawat -------------- next part -------------- An HTML attachment was scrubbed... URL: From vxanica at gmail.com Tue Mar 3 14:41:11 2015 From: vxanica at gmail.com (Song Zhang) Date: Tue, 3 Mar 2015 22:41:11 +0800 Subject: [Haskell-beginners] "Template Haskell and higher order meta programming." Message-ID: I generally have 2 questions. I am writing some functions to derive typeclass instances with a package called derive. I just want to get rid of using Derivation type with a stupid reason. I want use just Name type. How can I defined a function with type derivings :: Name -> Name -> Q [Dec] by using function derive :: Derivation -> Name -> Q [Dec] so that user can just write derivings ''Eq ''D instead of derive makeEq ''D? > {-# LANGUAGE TemplateHaskell #-} > import Data.DeriveTH -- in derive package > import Language.Haskell.TH > import qualified Language.Haskell.TH.Syntax as S > data D = D > derivings :: Name -> String -> Q Exp > derivings cla typ = do > let makeClassName = mkName $ "make" ++ nameBase cla > a <- [| derive makeClassName (mkName typ) |] > return a > instance S.Lift Name where > lift x = varE x Main> :t derivings ''Eq "D" derivings ''Eq "D" :: Q Exp Main> :t $(derivings ''Eq "D") $(derivings ''Eq "D") :: Q [Dec] There is no problem to quote twice in other file in order to get the declaration. Maybe it should called second order meta programming. But the following has problems: > derivings'' :: Name -> Name -> Q Exp > derivings'' cla typ = do > let makeClassName = mkName $ "make" ++ nameBase cla > a <- [| derive makeClassName typ |] > return a Main> :t derivings'' derivings'' :: Name -> Name -> Q Exp Main> :t derivings'' ''Eq ''D derivings'' ''Eq ''D :: Q Exp Main> :t $(derivings'' ''Eq ''D) :1:3: Illegal variable name: ?D? When splicing a TH expression: Data.DeriveTH.derive makeEq (Language.Haskell.TH.Syntax.mkName Main.D) In the splice: $(derivings'' ''Eq ''D) In the first case I used String, it works. however, it is not workiing if I use D with a Name type. Cannot figure it out. My second question is that if my return type is Q [Exp] while the [Exp] can be further expanded into [Dec]. How can I do it to expand [Exp] into [Dec]? Do we have a function for $ in $(thcode_with_Q_Exp) so that I do not need to splice each Exp value? Best wishes Song -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjakway at nyu.edu Tue Mar 3 19:27:08 2015 From: tjakway at nyu.edu (Thomas Jakway) Date: Tue, 03 Mar 2015 14:27:08 -0500 Subject: [Haskell-beginners] FFI Problems In-Reply-To: References: <54F1C085.7020503@nyu.edu> Message-ID: <54F60B0C.3070706@nyu.edu> Thanks very much! This helped a lot (and you were right on #2... I really should have caught that). On 3/2/15 10:20 AM, Sylvain Henry wrote: > Hi, > > 1) You have a copy-paste error on the following line (s/bitrate/track) > track <- ((#peek struct music_metadata, bitrate) a) :: IO Int > > 2) By looking at the values you get in hexadecimal, you are reading > 64bits values when your C struct contains 32 bits values. If you use: > peek ... :: IO Int32, it should be ok. > > 3) From a style point of view, you could use Applicative operators > (from Control.Applicative) to avoid temporary names: > peek a = MusicMetaData > <$> liftM constantToCodec $ (((#peek struct music_metadata, > codec) a) :: IO Int32) > <*> fmap fromIntegral (((#peek struct music_metadata, length) > a) :: IO Int32) > <*> fmap fromIntegral (((#peek struct music_metadata, bitrate) > a) :: IO Int32) > <*> fmap fromIntegral (((#peek struct music_metadata, > channels) a) :: IO Int32) > <*> fmap fromIntegral (((#peek struct music_metadata, track) > a) :: IO Int32) > <*> (peekCString =<< (#peek struct music_metadata, title) a) > ... > > 4) In your constantToCodec function, you don't need the temporary > names for all the constants. > > Best regards, > Sylvain > > PS : recently I have been working on rewriting the FFI page on the > wiki to make it more beginner-friendly ;-). It is not totally finished > but I'm open to any comment. > https://www.haskell.org/wiki/Foreign_Function_Interface > > 2015-02-28 14:20 GMT+01:00 Thomas Jakway >: > > I'm very new to Haskell and am trying to write a "real" program to > motivate myself to learn it better (so far I've only gotten > through Project Euler problems after reading LYAH and most of > RWH). I'm using Taglib (https://github.com/taglib/taglib) to read > the metadata from a music file and print it. I have a struct > C-side (with C linkage) serving as the bridge between Taglib's C++ > and Haskell's FFI. A small demo program (compiled with gcc and > linked against the C++ object files) gives the correct results, > but Haskell is weirdly only getting /some /of it right. > Specifically, the C string fields are working but ints are not. > > The output from the C demo (what Haskell should be printing): > > music_metadata > title: It's My Life, artist: Bon Jovi, album: Bon Jovi > Greatest Hits - The Ultimate Collection > comment: , genre: Rock, track: 3, > length: 224, bitrate: 256, channels: 2, > codec: 768 > > The output from Haskell: > > MusicMetadata {codec = UNKNOWN, length = 1099511628000, bitrate = > 8589934848 , channels = 12884901890, track = > 8589934848 , title = "It's My Life", artist = "Bon > Jovi", album = "Bon Jovi Greatest Hits - The Ultimate Collection", > comment = "", genre = "Rock"} > > I would have expected it to work or not work at all, but did not > anticipate getting only some of it right. > > I was going to include snippets from my hsc file but given how new > I am to Haskell I don't trust myself to assume where the problem > is, so sorry if this is way too long: > > {-# LANGUAGE CPP, ForeignFunctionInterface #-} > > module MusicReader > ( Codec, > MusicMetadata, > readMusicMetadata > ) where > > import Control.Monad > import Foreign > import Foreign.C.Types > import Foreign.C.String > import System.IO.Unsafe as Unsafe > > #include "CodecDefines.h" > #include "MusicReader.h" > > constantToCodec code > | code == mp3 = MP3 > | code == flac = FLAC > | code == ogg = OGG_VORBIS > | code == mp4 = MP4 > | code == mpeg = MPEG > | code == none = NONE > | code == unknown = UNKNOWN > | otherwise = UNKNOWN > where mp3 = #const MP3_CODEC > flac = #const FLAC_CODEC > ogg = #const OGG_VORBIS_CODEC > mp4 = #const MP4_CODEC > mpeg = #const MPEG_CODEC > none = #const NO_EXTENSION > unknown = #const UNKNOWN_EXTENSION > > data Codec = MP3 | FLAC | OGG_VORBIS | MP4 | MPEG | NONE | UNKNOWN > deriving (Show) > > data MusicMetadata = MusicMetadata { codec :: Codec, > length :: Int, > bitrate :: Int, > channels :: Int, > track :: Int, > title :: String, > artist :: String, > album :: String, > comment :: String, > genre :: String } deriving (Show) > > instance Storable MusicMetadata where > sizeOf _ = (#size struct music_metadata) > alignment _ = alignment (undefined::CDouble) > peek a = do > codec <- liftM constantToCodec $ (((#peek struct > music_metadata, codec) a) :: IO Int) > length <- ((#peek struct music_metadata, length) a) :: IO Int > bitrate <- ((#peek struct music_metadata, bitrate) a) :: > IO Int > channels <- ((#peek struct music_metadata, channels) a) :: > IO Int > track <- ((#peek struct music_metadata, bitrate) a) :: IO Int > title <- ((#peek struct music_metadata, title) a) :: IO > CString > artist <- ((#peek struct music_metadata, artist) a) :: IO > CString > album <- ((#peek struct music_metadata, album) a) :: IO > CString > comment <- ((#peek struct music_metadata, comment) a) :: > IO CString > genre <- ((#peek struct music_metadata, genre) a) :: IO > CString > --FIXME: find replacement for temporary names > marshalledTitle <- peekCString title > marshalledArtist <- peekCString artist > marshalledAlbum <- peekCString album > marshalledComment <- peekCString comment > marshalledGenre <- peekCString genre > return (MusicMetadata codec length bitrate channels track > marshalledTitle marshalledArtist marshalledAlbum marshalledComment > marshalledGenre) > poke a = undefined > > --This is the "primitive" FFI call--calls the C function and gets > a pointer > --in return > --TODO: write a higher level function this module should export > that calls > --primReadMusicMetadata and converts the C Pointer into the > Haskell data > --MusicMetadata > foreign import ccall unsafe "read_metadata" primReadMusicMetadata > :: CString -> IO (Ptr MusicMetadata) > > --convert the Haskell string to a CString, call into the FFI then > --dereference the resulting pointer > readMusicMetadata a = join $ withCString a $ \cs -> ((liftM peek) > $ primReadMusicMetadata cs) > > > > Here's the struct in MusicReader.h (in an extern C block): > struct music_metadata > { > int codec; > int length, > bitrate, > channels; > int track; > char *title, > *artist, > *album, > *comment, > *genre; > }; > > > with the corresponding call: > struct music_metadata* read_metadata(char*); > > > I've tried playing around with the alignment but it didn't do > anything. I also tried declaring the struct's fields as int32_t > which also did nothing. > > The C demo in question is a very simple: > > #include > #include "MusicReader.h" > > #define FILENAME "Its_My_Life.m4a" > > int main() > { > struct music_metadata* metadata = read_metadata(FILENAME); > printf("music_metadata\ntitle: %s,\tartist: %s,\talbum: %s\n", > metadata->title, metadata->artist, metadata->album); > printf("comment: %s,\tgenre: %s,\ttrack: %d,\n", > metadata->comment, metadata->genre, metadata->track); > printf("length: %d,\tbitrate: %d,\tchannels: %d,\n", > metadata->length, metadata->bitrate, metadata->channels); > printf("codec: %d\n"); > > } > > It just reads the metadata into the struct and prints the fields. > > I've gotten the impression of the Haskell FFI being very > beginner-unfriendly, which isn't surprising but still > disappointing because it would be a great opportunity to replace > some projects with Haskell. > > Any help is appreciated, including general feedback on my code! > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: From objitsu at gmail.com Tue Mar 3 20:19:36 2015 From: objitsu at gmail.com (emacstheviking) Date: Tue, 3 Mar 2015 20:19:36 +0000 Subject: [Haskell-beginners] LTS is good but... Message-ID: I started an OpenGL project within an LTS sandbox as guided on another post and, somewhat foolishly it would see, I did a "cabal install cabal-install" when prompted that a new version was available. The very next time I tried to work on my code.... I got this: bash-3.2$ pwd /Users/seancharles/Documents/Coding/haskell/lts1 bash-3.2$ cabal build cabal: You need to re-run the 'configure' command. The version of Cabal being used has changed (was Cabal-1.20.0.1, now Cabal-1.16.0). bash-3.2$ cabal configure Resolving dependencies... Configuring lts1-0.1.0.0... cabal: At least the following dependencies are missing: base ==4.7.* bash-3.2$ cabal build cabal: You need to re-run the 'configure' command. The version of Cabal being used has changed (was Cabal-1.20.0.1, now Cabal-1.16.0). bash-3.2$ ls -l total 112 -rw-r--r-- 1 seancharles staff 19 Mar 2 12:53 LICENCSE -rw-r--r-- 1 seancharles staff 552 Mar 3 20:09 Main.hs -rw-r--r-- 1 seancharles staff 477 Mar 3 20:07 Main.hs~ -rw-r--r-- 1 seancharles staff 46 Mar 2 12:52 Setup.hs -rw-r--r-- 1 seancharles staff 30198 Mar 2 12:51 cabal.config -rw-r--r-- 1 seancharles staff 1090 Mar 2 12:51 cabal.sandbox.config drwxr-xr-x 5 seancharles staff 170 Mar 2 12:53 dist -rw-r--r-- 1 seancharles staff 1932 Mar 2 12:52 lts1.cabal bash-3.2$ So, welcome to a different kind of hell, "cabal version hell" perhaps? Can anybody help me get it running again? Thanks. Sean. -------------- next part -------------- An HTML attachment was scrubbed... URL: From objitsu at gmail.com Tue Mar 3 20:20:59 2015 From: objitsu at gmail.com (emacstheviking) Date: Tue, 3 Mar 2015 20:20:59 +0000 Subject: [Haskell-beginners] LTS is good but... In-Reply-To: References: Message-ID: Forgot to add that somehow, despite the upgrade, my cabal version has gone backwards from 1.20.0.1 to 1.16.0 WTF? On 3 March 2015 at 20:19, emacstheviking wrote: > I started an OpenGL project within an LTS sandbox as guided on another > post and, somewhat foolishly it would see, I did a "cabal install > cabal-install" when prompted that a new version was available. > > The very next time I tried to work on my code.... I got this: > > bash-3.2$ pwd > /Users/seancharles/Documents/Coding/haskell/lts1 > bash-3.2$ cabal build > cabal: You need to re-run the 'configure' command. The version of Cabal > being > used has changed (was Cabal-1.20.0.1, now Cabal-1.16.0). > bash-3.2$ cabal configure > Resolving dependencies... > Configuring lts1-0.1.0.0... > cabal: At least the following dependencies are missing: > base ==4.7.* > bash-3.2$ cabal build > cabal: You need to re-run the 'configure' command. The version of Cabal > being > used has changed (was Cabal-1.20.0.1, now Cabal-1.16.0). > bash-3.2$ ls -l > total 112 > -rw-r--r-- 1 seancharles staff 19 Mar 2 12:53 LICENCSE > -rw-r--r-- 1 seancharles staff 552 Mar 3 20:09 Main.hs > -rw-r--r-- 1 seancharles staff 477 Mar 3 20:07 Main.hs~ > -rw-r--r-- 1 seancharles staff 46 Mar 2 12:52 Setup.hs > -rw-r--r-- 1 seancharles staff 30198 Mar 2 12:51 cabal.config > -rw-r--r-- 1 seancharles staff 1090 Mar 2 12:51 cabal.sandbox.config > drwxr-xr-x 5 seancharles staff 170 Mar 2 12:53 dist > -rw-r--r-- 1 seancharles staff 1932 Mar 2 12:52 lts1.cabal > bash-3.2$ > > So, welcome to a different kind of hell, "cabal version hell" perhaps? > > Can anybody help me get it running again? > Thanks. > Sean. > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From michael at snoyman.com Tue Mar 3 20:43:34 2015 From: michael at snoyman.com (Michael Snoyman) Date: Tue, 03 Mar 2015 20:43:34 +0000 Subject: [Haskell-beginners] LTS is good but... References: Message-ID: Funny that there's an issue being discussed in the cabal issue tracker right now[1] similar to this. But the report you're giving here is particularly strange. Cabal-1.16 implies that you're using GHC 7.6, which is supported by the claim that base 4.7 isn't available. I'd recommend starting off with running the following commands and pasting the output: ghc --version which ghc cabal --version which cabal [1] https://github.com/haskell/cabal/issues/2438 On Tue, Mar 3, 2015 at 10:21 PM emacstheviking wrote: > Forgot to add that somehow, despite the upgrade, my cabal version has gone > backwards from 1.20.0.1 to 1.16.0 > > WTF? > > > On 3 March 2015 at 20:19, emacstheviking wrote: > >> I started an OpenGL project within an LTS sandbox as guided on another >> post and, somewhat foolishly it would see, I did a "cabal install >> cabal-install" when prompted that a new version was available. >> >> The very next time I tried to work on my code.... I got this: >> >> bash-3.2$ pwd >> /Users/seancharles/Documents/Coding/haskell/lts1 >> bash-3.2$ cabal build >> cabal: You need to re-run the 'configure' command. The version of Cabal >> being >> used has changed (was Cabal-1.20.0.1, now Cabal-1.16.0). >> bash-3.2$ cabal configure >> Resolving dependencies... >> Configuring lts1-0.1.0.0... >> cabal: At least the following dependencies are missing: >> base ==4.7.* >> bash-3.2$ cabal build >> cabal: You need to re-run the 'configure' command. The version of Cabal >> being >> used has changed (was Cabal-1.20.0.1, now Cabal-1.16.0). >> bash-3.2$ ls -l >> total 112 >> -rw-r--r-- 1 seancharles staff 19 Mar 2 12:53 LICENCSE >> -rw-r--r-- 1 seancharles staff 552 Mar 3 20:09 Main.hs >> -rw-r--r-- 1 seancharles staff 477 Mar 3 20:07 Main.hs~ >> -rw-r--r-- 1 seancharles staff 46 Mar 2 12:52 Setup.hs >> -rw-r--r-- 1 seancharles staff 30198 Mar 2 12:51 cabal.config >> -rw-r--r-- 1 seancharles staff 1090 Mar 2 12:51 cabal.sandbox.config >> drwxr-xr-x 5 seancharles staff 170 Mar 2 12:53 dist >> -rw-r--r-- 1 seancharles staff 1932 Mar 2 12:52 lts1.cabal >> bash-3.2$ >> >> So, welcome to a different kind of hell, "cabal version hell" perhaps? >> >> Can anybody help me get it running again? >> Thanks. >> Sean. >> >> > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From electriclightheads at gmail.com Wed Mar 4 03:22:11 2015 From: electriclightheads at gmail.com ('2+) Date: Wed, 4 Mar 2015 12:22:11 +0900 Subject: [Haskell-beginners] fractal x = fractal [y - head x + z | y <- x, z <- x] with take doesnt end Message-ID: <4F515C47-6CAE-4DDB-B436-61CDD653F66B@gmail.com> hi! since my fractal :: [Int] -> [Int] fractal x = [y - head x + z | y <- x, z <- x] seems to be working fine with something like: take 300 $ cycle $ fractal $ fractal $ [11..17] ++ [55..77] wanted to twist the function to something totally recursive but: fractal x = fractal [y - head x + z | y <- x, z <- x] experimented with: take 300 $ fractal $ [11..17] ++ [55..77] doesnt end its process and eat up the RAM any hints to solve this issue? thank you ----- 2g --- http://sarigama.namaste.jp From sumit.sahrawat.apm13 at iitbhu.ac.in Wed Mar 4 03:56:08 2015 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Wed, 4 Mar 2015 09:26:08 +0530 Subject: [Haskell-beginners] fractal x = fractal [y - head x + z | y <- x, z <- x] with take doesnt end In-Reply-To: <4F515C47-6CAE-4DDB-B436-61CDD653F66B@gmail.com> References: <4F515C47-6CAE-4DDB-B436-61CDD653F66B@gmail.com> Message-ID: Both the versions work for me. The one with two calls to fractal takes ~0.03 seconds, whereas the one with only one call takes ~0.01 seconds. All timings produced using (:set +s) in ghci. Also, that totally recursive definition is infinitely recursive. If you provide some more context, it will be easier to answer your question. Till now I don't exactly understand what the issue is. On 4 March 2015 at 08:52, '2+ wrote: > hi! > since my > > fractal :: [Int] -> [Int] > fractal x = [y - head x + z | y <- x, z <- x] > > seems to be working fine with something like: > > take 300 $ cycle $ fractal $ fractal $ [11..17] ++ [55..77] > > wanted to twist the function to something totally recursive > but: > > fractal x = fractal [y - head x + z | y <- x, z <- x] > > experimented with: > > take 300 $ fractal $ [11..17] ++ [55..77] > > doesnt end its process and eat up the RAM > > any hints to solve this issue? > > thank you > > ----- 2g --- > http://sarigama.namaste.jp > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -- Regards Sumit Sahrawat -------------- next part -------------- An HTML attachment was scrubbed... URL: From raguay at customct.com Wed Mar 4 05:38:24 2015 From: raguay at customct.com (Richard Guay) Date: Wed, 04 Mar 2015 12:38:24 +0700 Subject: [Haskell-beginners] Alfred Programs in Haskell Message-ID: <54F69A50.4030308@customct.com> Hi, I am using Haskell to write Alfred programs, but I have run into an issue I just can not fix. The routine for reading a data file in a application specific location for Alfred never detects the file as non-existant. It then dies on the read. Here is the code: getAlfredCacheFileContents :: String -> IO (String) getAlfredCacheFileContents fileName = do h <- getHomeDirectory fExist <- doesFileExist $ h ++ cacheDirBasic ++ getBundleID ++ "/" ++ fileName if fExist then do contents <- readFile $ h ++ cacheDirBasic ++ getBundleID ++ "/" ++ fileName return contents else return "" I just installed the latest version on my Mac Air. It always does the call to readFile, even when the file doesn't exist. -- Sent with Postbox -------------- next part -------------- An HTML attachment was scrubbed... URL: From mike at proclivis.com Wed Mar 4 06:50:43 2015 From: mike at proclivis.com (Michael Jones) Date: Tue, 3 Mar 2015 23:50:43 -0700 Subject: [Haskell-beginners] Google Summer of Code Message-ID: If any students are interested in Google Summer of Code projects, there is a Minnow Board project here: http://elinux.org/Minnowboard:GSoC2015 There is a Haskell project listed in the SMBus/PMBus section. Mike From objitsu at gmail.com Wed Mar 4 08:39:56 2015 From: objitsu at gmail.com (emacstheviking) Date: Wed, 4 Mar 2015 08:39:56 +0000 Subject: [Haskell-beginners] LTS is good but... In-Reply-To: References: Message-ID: As requested, iMac:~ vosabristol$ ghc --version The Glorious Glasgow Haskell Compilation System, version 7.8.3 which ghc /opt/local/bin/ghc Hmm.... it shows a macports instsallation of GHC... but I am sure that's how I git it... I *used* to use the OSX installation package but I thought a clean start using MacPorts would somehow change the mood... iMac:~ vosabristol$ cabal --version cabal-install version 1.16.0.2 using version 1.16.0 of the Cabal library iMac:~ vosabristol$ which cabal /usr/bin/cabal So... there is a possible case for *once again* performing a complete and utter removal of Haskell and its partners in crime and doing a fresh installation? Out of frustration I built OCaml and OPAM from sources last night but I'd still like to go with GHC! :) On 3 March 2015 at 20:43, Michael Snoyman wrote: > Funny that there's an issue being discussed in the cabal issue tracker > right now[1] similar to this. But the report you're giving here is > particularly strange. Cabal-1.16 implies that you're using GHC 7.6, which > is supported by the claim that base 4.7 isn't available. I'd recommend > starting off with running the following commands and pasting the output: > > ghc --version > which ghc > cabal --version > which cabal > > [1] https://github.com/haskell/cabal/issues/2438 > > On Tue, Mar 3, 2015 at 10:21 PM emacstheviking wrote: > >> Forgot to add that somehow, despite the upgrade, my cabal version has >> gone backwards from 1.20.0.1 to 1.16.0 >> >> WTF? >> >> >> On 3 March 2015 at 20:19, emacstheviking wrote: >> >>> I started an OpenGL project within an LTS sandbox as guided on another >>> post and, somewhat foolishly it would see, I did a "cabal install >>> cabal-install" when prompted that a new version was available. >>> >>> The very next time I tried to work on my code.... I got this: >>> >>> bash-3.2$ pwd >>> /Users/seancharles/Documents/Coding/haskell/lts1 >>> bash-3.2$ cabal build >>> cabal: You need to re-run the 'configure' command. The version of Cabal >>> being >>> used has changed (was Cabal-1.20.0.1, now Cabal-1.16.0). >>> bash-3.2$ cabal configure >>> Resolving dependencies... >>> Configuring lts1-0.1.0.0... >>> cabal: At least the following dependencies are missing: >>> base ==4.7.* >>> bash-3.2$ cabal build >>> cabal: You need to re-run the 'configure' command. The version of Cabal >>> being >>> used has changed (was Cabal-1.20.0.1, now Cabal-1.16.0). >>> bash-3.2$ ls -l >>> total 112 >>> -rw-r--r-- 1 seancharles staff 19 Mar 2 12:53 LICENCSE >>> -rw-r--r-- 1 seancharles staff 552 Mar 3 20:09 Main.hs >>> -rw-r--r-- 1 seancharles staff 477 Mar 3 20:07 Main.hs~ >>> -rw-r--r-- 1 seancharles staff 46 Mar 2 12:52 Setup.hs >>> -rw-r--r-- 1 seancharles staff 30198 Mar 2 12:51 cabal.config >>> -rw-r--r-- 1 seancharles staff 1090 Mar 2 12:51 cabal.sandbox.config >>> drwxr-xr-x 5 seancharles staff 170 Mar 2 12:53 dist >>> -rw-r--r-- 1 seancharles staff 1932 Mar 2 12:52 lts1.cabal >>> bash-3.2$ >>> >>> So, welcome to a different kind of hell, "cabal version hell" perhaps? >>> >>> Can anybody help me get it running again? >>> Thanks. >>> Sean. >>> >>> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From michael at snoyman.com Wed Mar 4 09:13:41 2015 From: michael at snoyman.com (Michael Snoyman) Date: Wed, 04 Mar 2015 09:13:41 +0000 Subject: [Haskell-beginners] LTS is good but... References: Message-ID: I can't really explain the details of what's going on here. It seems that in some cases different versions of the executables are being found, but I don't know why. Wiping out your sandbox (cabal sandbox delete) and starting over may be sufficient to recover. On Wed, Mar 4, 2015 at 11:11 AM emacstheviking wrote: > As requested, > > iMac:~ vosabristol$ ghc --version > The Glorious Glasgow Haskell Compilation System, version 7.8.3 > > which ghc > /opt/local/bin/ghc > > Hmm.... it shows a macports instsallation of GHC... but I am sure that's > how I git it... I *used* to use the OSX installation package but I thought > a clean start using MacPorts would somehow change the mood... > > iMac:~ vosabristol$ cabal --version > cabal-install version 1.16.0.2 > using version 1.16.0 of the Cabal library > > iMac:~ vosabristol$ which cabal > /usr/bin/cabal > > So... there is a possible case for *once again* performing a complete and > utter removal of Haskell and its partners in crime and doing a fresh > installation? > > > Out of frustration I built OCaml and OPAM from sources last night but I'd > still like to go with GHC! > > :) > > > On 3 March 2015 at 20:43, Michael Snoyman wrote: > >> Funny that there's an issue being discussed in the cabal issue tracker >> right now[1] similar to this. But the report you're giving here is >> particularly strange. Cabal-1.16 implies that you're using GHC 7.6, which >> is supported by the claim that base 4.7 isn't available. I'd recommend >> starting off with running the following commands and pasting the output: >> >> ghc --version >> which ghc >> cabal --version >> which cabal >> >> [1] https://github.com/haskell/cabal/issues/2438 >> >> On Tue, Mar 3, 2015 at 10:21 PM emacstheviking wrote: >> >>> Forgot to add that somehow, despite the upgrade, my cabal version has >>> gone backwards from 1.20.0.1 to 1.16.0 >>> >>> WTF? >>> >>> >>> On 3 March 2015 at 20:19, emacstheviking wrote: >>> >>>> I started an OpenGL project within an LTS sandbox as guided on another >>>> post and, somewhat foolishly it would see, I did a "cabal install >>>> cabal-install" when prompted that a new version was available. >>>> >>>> The very next time I tried to work on my code.... I got this: >>>> >>>> bash-3.2$ pwd >>>> /Users/seancharles/Documents/Coding/haskell/lts1 >>>> bash-3.2$ cabal build >>>> cabal: You need to re-run the 'configure' command. The version of Cabal >>>> being >>>> used has changed (was Cabal-1.20.0.1, now Cabal-1.16.0). >>>> bash-3.2$ cabal configure >>>> Resolving dependencies... >>>> Configuring lts1-0.1.0.0... >>>> cabal: At least the following dependencies are missing: >>>> base ==4.7.* >>>> bash-3.2$ cabal build >>>> cabal: You need to re-run the 'configure' command. The version of Cabal >>>> being >>>> used has changed (was Cabal-1.20.0.1, now Cabal-1.16.0). >>>> bash-3.2$ ls -l >>>> total 112 >>>> -rw-r--r-- 1 seancharles staff 19 Mar 2 12:53 LICENCSE >>>> -rw-r--r-- 1 seancharles staff 552 Mar 3 20:09 Main.hs >>>> -rw-r--r-- 1 seancharles staff 477 Mar 3 20:07 Main.hs~ >>>> -rw-r--r-- 1 seancharles staff 46 Mar 2 12:52 Setup.hs >>>> -rw-r--r-- 1 seancharles staff 30198 Mar 2 12:51 cabal.config >>>> -rw-r--r-- 1 seancharles staff 1090 Mar 2 12:51 >>>> cabal.sandbox.config >>>> drwxr-xr-x 5 seancharles staff 170 Mar 2 12:53 dist >>>> -rw-r--r-- 1 seancharles staff 1932 Mar 2 12:52 lts1.cabal >>>> bash-3.2$ >>>> >>>> So, welcome to a different kind of hell, "cabal version hell" perhaps? >>>> >>>> Can anybody help me get it running again? >>>> Thanks. >>>> Sean. >>>> >>>> >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From d12frosted at icloud.com Wed Mar 4 09:21:29 2015 From: d12frosted at icloud.com (Boris) Date: Wed, 04 Mar 2015 11:21:29 +0200 Subject: [Haskell-beginners] LTS is good but... In-Reply-To: References: Message-ID: Hey, Check your $PATH variable. It looks like the macports installation directory has precedence over /user/local/bin/. But you also might want to remove the old version installed via macports. ~ d12frosted On March 4, 2015 at 11:11:05, emacstheviking (objitsu at gmail.com) wrote: As requested, iMac:~ vosabristol$ ghc --version The Glorious Glasgow Haskell Compilation System, version 7.8.3 which ghc /opt/local/bin/ghc Hmm.... it shows a macports instsallation of GHC... but I am sure that's how I git it... I *used* to use the OSX installation package but I thought a clean start using MacPorts would somehow change the mood... iMac:~ vosabristol$ cabal --version cabal-install version 1.16.0.2 using version 1.16.0 of the Cabal library iMac:~ vosabristol$ which cabal /usr/bin/cabal So... there is a possible case for *once again* performing a complete and utter removal of Haskell and its partners in crime and doing a fresh installation? Out of frustration I built OCaml and OPAM from sources last night but I'd still like to go with GHC! :) On 3 March 2015 at 20:43, Michael Snoyman wrote: Funny that there's an issue being discussed in the cabal issue tracker right now[1] similar to this.?But the report you're giving here is particularly strange. Cabal-1.16 implies that you're using GHC 7.6, which is supported by the claim that base 4.7 isn't available. I'd recommend starting off with running the following commands and pasting the output: ghc --version which ghc cabal --version which cabal [1]?https://github.com/haskell/cabal/issues/2438 On Tue, Mar 3, 2015 at 10:21 PM emacstheviking wrote: Forgot to add that somehow, despite the upgrade, my cabal version has gone backwards from 1.20.0.1 to 1.16.0 WTF? On 3 March 2015 at 20:19, emacstheviking wrote: I started an OpenGL project within an LTS sandbox as guided on another post and, somewhat foolishly it would see, I did a "cabal install cabal-install" when prompted that a new version was available. The very next time I tried to work on my code.... I got this: bash-3.2$ pwd /Users/seancharles/Documents/Coding/haskell/lts1 bash-3.2$ cabal build cabal: You need to re-run the 'configure' command. The version of Cabal being used has changed (was Cabal-1.20.0.1, now Cabal-1.16.0). bash-3.2$ cabal configure Resolving dependencies... Configuring lts1-0.1.0.0... cabal: At least the following dependencies are missing: base ==4.7.* bash-3.2$ cabal build cabal: You need to re-run the 'configure' command. The version of Cabal being used has changed (was Cabal-1.20.0.1, now Cabal-1.16.0). bash-3.2$ ls -l total 112 -rw-r--r-- ?1 seancharles ?staff ? ? 19 Mar ?2 12:53 LICENCSE -rw-r--r-- ?1 seancharles ?staff ? ?552 Mar ?3 20:09 Main.hs -rw-r--r-- ?1 seancharles ?staff ? ?477 Mar ?3 20:07 Main.hs~ -rw-r--r-- ?1 seancharles ?staff ? ? 46 Mar ?2 12:52 Setup.hs -rw-r--r-- ?1 seancharles ?staff ?30198 Mar ?2 12:51 cabal.config -rw-r--r-- ?1 seancharles ?staff ? 1090 Mar ?2 12:51 cabal.sandbox.config drwxr-xr-x ?5 seancharles ?staff ? ?170 Mar ?2 12:53 dist -rw-r--r-- ?1 seancharles ?staff ? 1932 Mar ?2 12:52 lts1.cabal bash-3.2$? So, welcome to a different kind of hell, "cabal version hell" perhaps? Can anybody help me get it running again? Thanks. Sean. _______________________________________________ Beginners mailing list Beginners at haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners _______________________________________________ Beginners mailing list Beginners at haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners _______________________________________________ Beginners mailing list Beginners at haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: From objitsu at gmail.com Wed Mar 4 09:25:28 2015 From: objitsu at gmail.com (emacstheviking) Date: Wed, 4 Mar 2015 09:25:28 +0000 Subject: [Haskell-beginners] LTS is good but... In-Reply-To: References: Message-ID: Agreed Michael! I am currently wiping all Mac Ports packages and I will perform a clean up of /Library/Haskell etc. What is the *preferred* way to get the lastest for OSX: Using homebrew, macports or the Haskell Platform. I *used* to use the platform installer but for some reason (cabal I expect!) I started trying out other ways... I think actually I will go the platform packager again... On 4 March 2015 at 09:13, Michael Snoyman wrote: > I can't really explain the details of what's going on here. It seems that > in some cases different versions of the executables are being found, but I > don't know why. Wiping out your sandbox (cabal sandbox delete) and starting > over may be sufficient to recover. > > On Wed, Mar 4, 2015 at 11:11 AM emacstheviking wrote: > >> As requested, >> >> iMac:~ vosabristol$ ghc --version >> The Glorious Glasgow Haskell Compilation System, version 7.8.3 >> >> which ghc >> /opt/local/bin/ghc >> >> Hmm.... it shows a macports instsallation of GHC... but I am sure that's >> how I git it... I *used* to use the OSX installation package but I thought >> a clean start using MacPorts would somehow change the mood... >> >> iMac:~ vosabristol$ cabal --version >> cabal-install version 1.16.0.2 >> using version 1.16.0 of the Cabal library >> >> iMac:~ vosabristol$ which cabal >> /usr/bin/cabal >> >> So... there is a possible case for *once again* performing a complete and >> utter removal of Haskell and its partners in crime and doing a fresh >> installation? >> >> >> Out of frustration I built OCaml and OPAM from sources last night but I'd >> still like to go with GHC! >> >> :) >> >> >> On 3 March 2015 at 20:43, Michael Snoyman wrote: >> >>> Funny that there's an issue being discussed in the cabal issue tracker >>> right now[1] similar to this. But the report you're giving here is >>> particularly strange. Cabal-1.16 implies that you're using GHC 7.6, which >>> is supported by the claim that base 4.7 isn't available. I'd recommend >>> starting off with running the following commands and pasting the output: >>> >>> ghc --version >>> which ghc >>> cabal --version >>> which cabal >>> >>> [1] https://github.com/haskell/cabal/issues/2438 >>> >>> On Tue, Mar 3, 2015 at 10:21 PM emacstheviking >>> wrote: >>> >>>> Forgot to add that somehow, despite the upgrade, my cabal version has >>>> gone backwards from 1.20.0.1 to 1.16.0 >>>> >>>> WTF? >>>> >>>> >>>> On 3 March 2015 at 20:19, emacstheviking wrote: >>>> >>>>> I started an OpenGL project within an LTS sandbox as guided on another >>>>> post and, somewhat foolishly it would see, I did a "cabal install >>>>> cabal-install" when prompted that a new version was available. >>>>> >>>>> The very next time I tried to work on my code.... I got this: >>>>> >>>>> bash-3.2$ pwd >>>>> /Users/seancharles/Documents/Coding/haskell/lts1 >>>>> bash-3.2$ cabal build >>>>> cabal: You need to re-run the 'configure' command. The version of >>>>> Cabal being >>>>> used has changed (was Cabal-1.20.0.1, now Cabal-1.16.0). >>>>> bash-3.2$ cabal configure >>>>> Resolving dependencies... >>>>> Configuring lts1-0.1.0.0... >>>>> cabal: At least the following dependencies are missing: >>>>> base ==4.7.* >>>>> bash-3.2$ cabal build >>>>> cabal: You need to re-run the 'configure' command. The version of >>>>> Cabal being >>>>> used has changed (was Cabal-1.20.0.1, now Cabal-1.16.0). >>>>> bash-3.2$ ls -l >>>>> total 112 >>>>> -rw-r--r-- 1 seancharles staff 19 Mar 2 12:53 LICENCSE >>>>> -rw-r--r-- 1 seancharles staff 552 Mar 3 20:09 Main.hs >>>>> -rw-r--r-- 1 seancharles staff 477 Mar 3 20:07 Main.hs~ >>>>> -rw-r--r-- 1 seancharles staff 46 Mar 2 12:52 Setup.hs >>>>> -rw-r--r-- 1 seancharles staff 30198 Mar 2 12:51 cabal.config >>>>> -rw-r--r-- 1 seancharles staff 1090 Mar 2 12:51 >>>>> cabal.sandbox.config >>>>> drwxr-xr-x 5 seancharles staff 170 Mar 2 12:53 dist >>>>> -rw-r--r-- 1 seancharles staff 1932 Mar 2 12:52 lts1.cabal >>>>> bash-3.2$ >>>>> >>>>> So, welcome to a different kind of hell, "cabal version hell" perhaps? >>>>> >>>>> Can anybody help me get it running again? >>>>> Thanks. >>>>> Sean. >>>>> >>>>> >>>> _______________________________________________ >>>> Beginners mailing list >>>> Beginners at haskell.org >>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>> >>> >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >>> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From michael at snoyman.com Wed Mar 4 09:28:43 2015 From: michael at snoyman.com (Michael Snoyman) Date: Wed, 04 Mar 2015 09:28:43 +0000 Subject: [Haskell-beginners] LTS is good but... References: Message-ID: I'd recommend looking at: http://www.stackage.org/install#mac-os-x https://github.com/bitemyapp/learnhaskell/blob/master/README.md#mac-os-x I don't generally recommend using the platform installer, it ends up pegging libraries to old versions which causes dependency problems, or in some cases have known bugs. On Wed, Mar 4, 2015 at 11:26 AM emacstheviking wrote: > Agreed Michael! > > I am currently wiping all Mac Ports packages and I will perform a clean up > of /Library/Haskell etc. > > What is the *preferred* way to get the lastest for OSX: Using homebrew, > macports or the Haskell Platform. I *used* to use the platform installer > but for some reason (cabal I expect!) I started trying out other ways... > > I think actually I will go the platform packager again... > > On 4 March 2015 at 09:13, Michael Snoyman wrote: > >> I can't really explain the details of what's going on here. It seems that >> in some cases different versions of the executables are being found, but I >> don't know why. Wiping out your sandbox (cabal sandbox delete) and starting >> over may be sufficient to recover. >> >> On Wed, Mar 4, 2015 at 11:11 AM emacstheviking wrote: >> >>> As requested, >>> >>> iMac:~ vosabristol$ ghc --version >>> The Glorious Glasgow Haskell Compilation System, version 7.8.3 >>> >>> which ghc >>> /opt/local/bin/ghc >>> >>> Hmm.... it shows a macports instsallation of GHC... but I am sure that's >>> how I git it... I *used* to use the OSX installation package but I thought >>> a clean start using MacPorts would somehow change the mood... >>> >>> iMac:~ vosabristol$ cabal --version >>> cabal-install version 1.16.0.2 >>> using version 1.16.0 of the Cabal library >>> >>> iMac:~ vosabristol$ which cabal >>> /usr/bin/cabal >>> >>> So... there is a possible case for *once again* performing a complete >>> and utter removal of Haskell and its partners in crime and doing a fresh >>> installation? >>> >>> >>> Out of frustration I built OCaml and OPAM from sources last night but >>> I'd still like to go with GHC! >>> >>> :) >>> >>> >>> On 3 March 2015 at 20:43, Michael Snoyman wrote: >>> >>>> Funny that there's an issue being discussed in the cabal issue tracker >>>> right now[1] similar to this. But the report you're giving here is >>>> particularly strange. Cabal-1.16 implies that you're using GHC 7.6, which >>>> is supported by the claim that base 4.7 isn't available. I'd recommend >>>> starting off with running the following commands and pasting the output: >>>> >>>> ghc --version >>>> which ghc >>>> cabal --version >>>> which cabal >>>> >>>> [1] https://github.com/haskell/cabal/issues/2438 >>>> >>>> On Tue, Mar 3, 2015 at 10:21 PM emacstheviking >>>> wrote: >>>> >>>>> Forgot to add that somehow, despite the upgrade, my cabal version has >>>>> gone backwards from 1.20.0.1 to 1.16.0 >>>>> >>>>> WTF? >>>>> >>>>> >>>>> On 3 March 2015 at 20:19, emacstheviking wrote: >>>>> >>>>>> I started an OpenGL project within an LTS sandbox as guided on >>>>>> another post and, somewhat foolishly it would see, I did a "cabal install >>>>>> cabal-install" when prompted that a new version was available. >>>>>> >>>>>> The very next time I tried to work on my code.... I got this: >>>>>> >>>>>> bash-3.2$ pwd >>>>>> /Users/seancharles/Documents/Coding/haskell/lts1 >>>>>> bash-3.2$ cabal build >>>>>> cabal: You need to re-run the 'configure' command. The version of >>>>>> Cabal being >>>>>> used has changed (was Cabal-1.20.0.1, now Cabal-1.16.0). >>>>>> bash-3.2$ cabal configure >>>>>> Resolving dependencies... >>>>>> Configuring lts1-0.1.0.0... >>>>>> cabal: At least the following dependencies are missing: >>>>>> base ==4.7.* >>>>>> bash-3.2$ cabal build >>>>>> cabal: You need to re-run the 'configure' command. The version of >>>>>> Cabal being >>>>>> used has changed (was Cabal-1.20.0.1, now Cabal-1.16.0). >>>>>> bash-3.2$ ls -l >>>>>> total 112 >>>>>> -rw-r--r-- 1 seancharles staff 19 Mar 2 12:53 LICENCSE >>>>>> -rw-r--r-- 1 seancharles staff 552 Mar 3 20:09 Main.hs >>>>>> -rw-r--r-- 1 seancharles staff 477 Mar 3 20:07 Main.hs~ >>>>>> -rw-r--r-- 1 seancharles staff 46 Mar 2 12:52 Setup.hs >>>>>> -rw-r--r-- 1 seancharles staff 30198 Mar 2 12:51 cabal.config >>>>>> -rw-r--r-- 1 seancharles staff 1090 Mar 2 12:51 >>>>>> cabal.sandbox.config >>>>>> drwxr-xr-x 5 seancharles staff 170 Mar 2 12:53 dist >>>>>> -rw-r--r-- 1 seancharles staff 1932 Mar 2 12:52 lts1.cabal >>>>>> bash-3.2$ >>>>>> >>>>>> So, welcome to a different kind of hell, "cabal version hell" perhaps? >>>>>> >>>>>> Can anybody help me get it running again? >>>>>> Thanks. >>>>>> Sean. >>>>>> >>>>>> >>>>> _______________________________________________ >>>>> Beginners mailing list >>>>> Beginners at haskell.org >>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>>> >>>> >>>> _______________________________________________ >>>> Beginners mailing list >>>> Beginners at haskell.org >>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>> >>>> >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From objitsu at gmail.com Wed Mar 4 09:31:02 2015 From: objitsu at gmail.com (emacstheviking) Date: Wed, 4 Mar 2015 09:31:02 +0000 Subject: [Haskell-beginners] LTS is good but... In-Reply-To: References: Message-ID: Aaaaaarrrrrrrrrggghhh! LMAO. 30 years ago it was all simpler.... but we didn't have Haskell! ;) Thanks. I will read that page and try again. On 4 March 2015 at 09:28, Michael Snoyman wrote: > I'd recommend looking at: > > http://www.stackage.org/install#mac-os-x > https://github.com/bitemyapp/learnhaskell/blob/master/README.md#mac-os-x > > I don't generally recommend using the platform installer, it ends up > pegging libraries to old versions which causes dependency problems, or in > some cases have known bugs. > > On Wed, Mar 4, 2015 at 11:26 AM emacstheviking wrote: > >> Agreed Michael! >> >> I am currently wiping all Mac Ports packages and I will perform a clean >> up of /Library/Haskell etc. >> >> What is the *preferred* way to get the lastest for OSX: Using homebrew, >> macports or the Haskell Platform. I *used* to use the platform installer >> but for some reason (cabal I expect!) I started trying out other ways... >> >> I think actually I will go the platform packager again... >> >> On 4 March 2015 at 09:13, Michael Snoyman wrote: >> >>> I can't really explain the details of what's going on here. It seems >>> that in some cases different versions of the executables are being found, >>> but I don't know why. Wiping out your sandbox (cabal sandbox delete) and >>> starting over may be sufficient to recover. >>> >>> On Wed, Mar 4, 2015 at 11:11 AM emacstheviking >>> wrote: >>> >>>> As requested, >>>> >>>> iMac:~ vosabristol$ ghc --version >>>> The Glorious Glasgow Haskell Compilation System, version 7.8.3 >>>> >>>> which ghc >>>> /opt/local/bin/ghc >>>> >>>> Hmm.... it shows a macports instsallation of GHC... but I am sure >>>> that's how I git it... I *used* to use the OSX installation package but I >>>> thought a clean start using MacPorts would somehow change the mood... >>>> >>>> iMac:~ vosabristol$ cabal --version >>>> cabal-install version 1.16.0.2 >>>> using version 1.16.0 of the Cabal library >>>> >>>> iMac:~ vosabristol$ which cabal >>>> /usr/bin/cabal >>>> >>>> So... there is a possible case for *once again* performing a complete >>>> and utter removal of Haskell and its partners in crime and doing a fresh >>>> installation? >>>> >>>> >>>> Out of frustration I built OCaml and OPAM from sources last night but >>>> I'd still like to go with GHC! >>>> >>>> :) >>>> >>>> >>>> On 3 March 2015 at 20:43, Michael Snoyman wrote: >>>> >>>>> Funny that there's an issue being discussed in the cabal issue tracker >>>>> right now[1] similar to this. But the report you're giving here is >>>>> particularly strange. Cabal-1.16 implies that you're using GHC 7.6, which >>>>> is supported by the claim that base 4.7 isn't available. I'd recommend >>>>> starting off with running the following commands and pasting the output: >>>>> >>>>> ghc --version >>>>> which ghc >>>>> cabal --version >>>>> which cabal >>>>> >>>>> [1] https://github.com/haskell/cabal/issues/2438 >>>>> >>>>> On Tue, Mar 3, 2015 at 10:21 PM emacstheviking >>>>> wrote: >>>>> >>>>>> Forgot to add that somehow, despite the upgrade, my cabal version has >>>>>> gone backwards from 1.20.0.1 to 1.16.0 >>>>>> >>>>>> WTF? >>>>>> >>>>>> >>>>>> On 3 March 2015 at 20:19, emacstheviking wrote: >>>>>> >>>>>>> I started an OpenGL project within an LTS sandbox as guided on >>>>>>> another post and, somewhat foolishly it would see, I did a "cabal install >>>>>>> cabal-install" when prompted that a new version was available. >>>>>>> >>>>>>> The very next time I tried to work on my code.... I got this: >>>>>>> >>>>>>> bash-3.2$ pwd >>>>>>> /Users/seancharles/Documents/Coding/haskell/lts1 >>>>>>> bash-3.2$ cabal build >>>>>>> cabal: You need to re-run the 'configure' command. The version of >>>>>>> Cabal being >>>>>>> used has changed (was Cabal-1.20.0.1, now Cabal-1.16.0). >>>>>>> bash-3.2$ cabal configure >>>>>>> Resolving dependencies... >>>>>>> Configuring lts1-0.1.0.0... >>>>>>> cabal: At least the following dependencies are missing: >>>>>>> base ==4.7.* >>>>>>> bash-3.2$ cabal build >>>>>>> cabal: You need to re-run the 'configure' command. The version of >>>>>>> Cabal being >>>>>>> used has changed (was Cabal-1.20.0.1, now Cabal-1.16.0). >>>>>>> bash-3.2$ ls -l >>>>>>> total 112 >>>>>>> -rw-r--r-- 1 seancharles staff 19 Mar 2 12:53 LICENCSE >>>>>>> -rw-r--r-- 1 seancharles staff 552 Mar 3 20:09 Main.hs >>>>>>> -rw-r--r-- 1 seancharles staff 477 Mar 3 20:07 Main.hs~ >>>>>>> -rw-r--r-- 1 seancharles staff 46 Mar 2 12:52 Setup.hs >>>>>>> -rw-r--r-- 1 seancharles staff 30198 Mar 2 12:51 cabal.config >>>>>>> -rw-r--r-- 1 seancharles staff 1090 Mar 2 12:51 >>>>>>> cabal.sandbox.config >>>>>>> drwxr-xr-x 5 seancharles staff 170 Mar 2 12:53 dist >>>>>>> -rw-r--r-- 1 seancharles staff 1932 Mar 2 12:52 lts1.cabal >>>>>>> bash-3.2$ >>>>>>> >>>>>>> So, welcome to a different kind of hell, "cabal version hell" >>>>>>> perhaps? >>>>>>> >>>>>>> Can anybody help me get it running again? >>>>>>> Thanks. >>>>>>> Sean. >>>>>>> >>>>>>> >>>>>> _______________________________________________ >>>>>> Beginners mailing list >>>>>> Beginners at haskell.org >>>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>>>> >>>>> >>>>> _______________________________________________ >>>>> Beginners mailing list >>>>> Beginners at haskell.org >>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>>> >>>>> >>>> _______________________________________________ >>>> Beginners mailing list >>>> Beginners at haskell.org >>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>> >>> >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >>> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From d12frosted at icloud.com Wed Mar 4 09:31:54 2015 From: d12frosted at icloud.com (Boris) Date: Wed, 04 Mar 2015 11:31:54 +0200 Subject: [Haskell-beginners] LTS is good but... In-Reply-To: References: Message-ID: Hey, Little addition to what Michael already sent you. To get ?the latest? you should build from sources :D But in case it?s ok for you to have ghc 7.8.3 and you don?t want to ./configure; make; make install, you might also check this installation script on github. On March 4, 2015 at 11:28:50, Michael Snoyman (michael at snoyman.com) wrote: I'd recommend looking at: http://www.stackage.org/install#mac-os-x https://github.com/bitemyapp/learnhaskell/blob/master/README.md#mac-os-x I don't generally recommend using the platform installer, it ends up pegging libraries to old versions which causes dependency problems, or in some cases have known bugs. On Wed, Mar 4, 2015 at 11:26 AM emacstheviking wrote: Agreed Michael! I am currently wiping all Mac Ports packages and I will perform a clean up of /Library/Haskell etc. What is the *preferred* way to get the lastest for OSX: Using homebrew, macports or the Haskell Platform. I *used* to use the platform installer but for some reason (cabal I expect!) I started trying out other ways... I think actually I will go the platform packager again... On 4 March 2015 at 09:13, Michael Snoyman wrote: I can't really explain the details of what's going on here. It seems that in some cases different versions of the executables are being found, but I don't know why. Wiping out your sandbox (cabal sandbox delete) and starting over may be sufficient to recover. On Wed, Mar 4, 2015 at 11:11 AM emacstheviking wrote: As requested, iMac:~ vosabristol$ ghc --version The Glorious Glasgow Haskell Compilation System, version 7.8.3 which ghc /opt/local/bin/ghc Hmm.... it shows a macports instsallation of GHC... but I am sure that's how I git it... I *used* to use the OSX installation package but I thought a clean start using MacPorts would somehow change the mood... iMac:~ vosabristol$ cabal --version cabal-install version 1.16.0.2 using version 1.16.0 of the Cabal library iMac:~ vosabristol$ which cabal /usr/bin/cabal So... there is a possible case for *once again* performing a complete and utter removal of Haskell and its partners in crime and doing a fresh installation? Out of frustration I built OCaml and OPAM from sources last night but I'd still like to go with GHC! :) On 3 March 2015 at 20:43, Michael Snoyman wrote: Funny that there's an issue being discussed in the cabal issue tracker right now[1] similar to this.?But the report you're giving here is particularly strange. Cabal-1.16 implies that you're using GHC 7.6, which is supported by the claim that base 4.7 isn't available. I'd recommend starting off with running the following commands and pasting the output: ghc --version which ghc cabal --version which cabal [1]?https://github.com/haskell/cabal/issues/2438 On Tue, Mar 3, 2015 at 10:21 PM emacstheviking wrote: Forgot to add that somehow, despite the upgrade, my cabal version has gone backwards from 1.20.0.1 to 1.16.0 WTF? On 3 March 2015 at 20:19, emacstheviking wrote: I started an OpenGL project within an LTS sandbox as guided on another post and, somewhat foolishly it would see, I did a "cabal install cabal-install" when prompted that a new version was available. The very next time I tried to work on my code.... I got this: bash-3.2$ pwd /Users/seancharles/Documents/Coding/haskell/lts1 bash-3.2$ cabal build cabal: You need to re-run the 'configure' command. The version of Cabal being used has changed (was Cabal-1.20.0.1, now Cabal-1.16.0). bash-3.2$ cabal configure Resolving dependencies... Configuring lts1-0.1.0.0... cabal: At least the following dependencies are missing: base ==4.7.* bash-3.2$ cabal build cabal: You need to re-run the 'configure' command. The version of Cabal being used has changed (was Cabal-1.20.0.1, now Cabal-1.16.0). bash-3.2$ ls -l total 112 -rw-r--r-- ?1 seancharles ?staff ? ? 19 Mar ?2 12:53 LICENCSE -rw-r--r-- ?1 seancharles ?staff ? ?552 Mar ?3 20:09 Main.hs -rw-r--r-- ?1 seancharles ?staff ? ?477 Mar ?3 20:07 Main.hs~ -rw-r--r-- ?1 seancharles ?staff ? ? 46 Mar ?2 12:52 Setup.hs -rw-r--r-- ?1 seancharles ?staff ?30198 Mar ?2 12:51 cabal.config -rw-r--r-- ?1 seancharles ?staff ? 1090 Mar ?2 12:51 cabal.sandbox.config drwxr-xr-x ?5 seancharles ?staff ? ?170 Mar ?2 12:53 dist -rw-r--r-- ?1 seancharles ?staff ? 1932 Mar ?2 12:52 lts1.cabal bash-3.2$? So, welcome to a different kind of hell, "cabal version hell" perhaps? Can anybody help me get it running again? Thanks. Sean. _______________________________________________ Beginners mailing list Beginners at haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners _______________________________________________ Beginners mailing list Beginners at haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners _______________________________________________ Beginners mailing list Beginners at haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners _______________________________________________ Beginners mailing list Beginners at haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners _______________________________________________ Beginners mailing list Beginners at haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners _______________________________________________ Beginners mailing list Beginners at haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: From haskell at elisehuard.be Wed Mar 4 09:32:53 2015 From: haskell at elisehuard.be (Elise Huard) Date: Wed, 4 Mar 2015 10:32:53 +0100 Subject: [Haskell-beginners] command-line interaction with running process Message-ID: Hi, I'm trying to do the following: implementing a command-line interface to directly interact with the state or the parameters of a looping/running process (a game, to be specific). My first thought is to fork a thread, passing in a TChan/TVar or similar to enable communication, and to have the command-line interface on the thread (getLine or haskelline ...). Another option would be to have a bona fide server-client interface (with sockets or others), to fork a thread again to run the server and to connect using the client library - which would allow me to use ghci and have transparent serialization under the hood. Are there known use cases? Am I missing something, for instance is it possible to interact with a running process directly using ghci? Any tips? Thank you, Elise From sumit.sahrawat.apm13 at iitbhu.ac.in Wed Mar 4 09:45:09 2015 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Wed, 4 Mar 2015 15:15:09 +0530 Subject: [Haskell-beginners] command-line interaction with running process In-Reply-To: References: Message-ID: If you decice upon the server-client architecture, you should take a look at zeromq. It is used extensively in IHaskell, so you can peek at the code there for a working example. Also, I believe a client-server architecture will be better as I personally enjoy games a lot more when they are multi-player. It makes the conversion from single-player to multi-player a non-destructive (or atleast less destructive) process. On 4 March 2015 at 15:02, Elise Huard wrote: > Hi, > > I'm trying to do the following: implementing a command-line interface > to directly interact with the state or the parameters of a > looping/running process (a game, to be specific). > > My first thought is to fork a thread, passing in a TChan/TVar or > similar to enable communication, and to have the command-line > interface on the thread (getLine or haskelline ...). > Another option would be to have a bona fide server-client interface > (with sockets or others), to fork a thread again to run the server and > to connect using the client library - which would allow me to use ghci > and have transparent serialization under the hood. > > Are there known use cases? Am I missing something, for instance is it > possible to interact with a running process directly using ghci? > Any tips? > > Thank you, > > Elise > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -- Regards Sumit Sahrawat -------------- next part -------------- An HTML attachment was scrubbed... URL: From haskell at elisehuard.be Wed Mar 4 09:58:26 2015 From: haskell at elisehuard.be (Elise Huard) Date: Wed, 4 Mar 2015 10:58:26 +0100 Subject: [Haskell-beginners] command-line interaction with running process In-Reply-To: References: Message-ID: Thanks for this answer - that's a good point. At this point it's mostly for (interactive) game/level design and testing though :) On 4 March 2015 at 10:45, Sumit Sahrawat, Maths & Computing, IIT (BHU) wrote: > If you decice upon the server-client architecture, you should take a look at > zeromq. > It is used extensively in IHaskell, so you can peek at the code there for a > working example. > > Also, I believe a client-server architecture will be better as I personally > enjoy games a lot more when they are multi-player. > It makes the conversion from single-player to multi-player a non-destructive > (or atleast less destructive) process. > > On 4 March 2015 at 15:02, Elise Huard wrote: >> >> Hi, >> >> I'm trying to do the following: implementing a command-line interface >> to directly interact with the state or the parameters of a >> looping/running process (a game, to be specific). >> >> My first thought is to fork a thread, passing in a TChan/TVar or >> similar to enable communication, and to have the command-line >> interface on the thread (getLine or haskelline ...). >> Another option would be to have a bona fide server-client interface >> (with sockets or others), to fork a thread again to run the server and >> to connect using the client library - which would allow me to use ghci >> and have transparent serialization under the hood. >> >> Are there known use cases? Am I missing something, for instance is it >> possible to interact with a running process directly using ghci? >> Any tips? >> >> Thank you, >> >> Elise >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > > > -- > Regards > > Sumit Sahrawat > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > From objitsu at gmail.com Wed Mar 4 10:44:45 2015 From: objitsu at gmail.com (emacstheviking) Date: Wed, 4 Mar 2015 10:44:45 +0000 Subject: [Haskell-beginners] command-line interaction with running process In-Reply-To: References: Message-ID: I did something similar a while back using a socket based "terminal session" into an OpenGL program so I could change things as it ran. It's viable. I used TVar I think and didn't encounter any issues. Sadly, the code has vanished but it worked well and wasn't that much code actually thanks to the libraries being good. On 4 March 2015 at 09:32, Elise Huard wrote: > Hi, > > I'm trying to do the following: implementing a command-line interface > to directly interact with the state or the parameters of a > looping/running process (a game, to be specific). > > My first thought is to fork a thread, passing in a TChan/TVar or > similar to enable communication, and to have the command-line > interface on the thread (getLine or haskelline ...). > Another option would be to have a bona fide server-client interface > (with sockets or others), to fork a thread again to run the server and > to connect using the client library - which would allow me to use ghci > and have transparent serialization under the hood. > > Are there known use cases? Am I missing something, for instance is it > possible to interact with a running process directly using ghci? > Any tips? > > Thank you, > > Elise > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From objitsu at gmail.com Wed Mar 4 10:45:39 2015 From: objitsu at gmail.com (emacstheviking) Date: Wed, 4 Mar 2015 10:45:39 +0000 Subject: [Haskell-beginners] LTS is good but... In-Reply-To: References: Message-ID: I am a 30+ years hacker Boris, building from source might just tempt me still!! HAHAHA My machine is now "clean" so I will decide how to play it! Thanks again everybody. On 4 March 2015 at 09:31, Boris wrote: > Hey, > > Little addition to what Michael already sent you. > > To get ?the latest? you should build from sources :D > > But in case it?s ok for you to have ghc 7.8.3 and you don?t want to ./configure; > make; make install, you might also check this installation script on > github . > > > > On March 4, 2015 at 11:28:50, Michael Snoyman (michael at snoyman.com) wrote: > > I'd recommend looking at: > > http://www.stackage.org/install#mac-os-x > https://github.com/bitemyapp/learnhaskell/blob/master/README.md#mac-os-x > > I don't generally recommend using the platform installer, it ends up > pegging libraries to old versions which causes dependency problems, or in > some cases have known bugs. > > On Wed, Mar 4, 2015 at 11:26 AM emacstheviking wrote: > >> Agreed Michael! >> >> I am currently wiping all Mac Ports packages and I will perform a clean >> up of /Library/Haskell etc. >> >> What is the *preferred* way to get the lastest for OSX: Using homebrew, >> macports or the Haskell Platform. I *used* to use the platform installer >> but for some reason (cabal I expect!) I started trying out other ways... >> >> I think actually I will go the platform packager again... >> >> On 4 March 2015 at 09:13, Michael Snoyman wrote: >> >>> I can't really explain the details of what's going on here. It seems >>> that in some cases different versions of the executables are being found, >>> but I don't know why. Wiping out your sandbox (cabal sandbox delete) and >>> starting over may be sufficient to recover. >>> >>> On Wed, Mar 4, 2015 at 11:11 AM emacstheviking >>> wrote: >>> >>>> As requested, >>>> >>>> iMac:~ vosabristol$ ghc --version >>>> The Glorious Glasgow Haskell Compilation System, version 7.8.3 >>>> >>>> which ghc >>>> /opt/local/bin/ghc >>>> >>>> Hmm.... it shows a macports instsallation of GHC... but I am sure >>>> that's how I git it... I *used* to use the OSX installation package but I >>>> thought a clean start using MacPorts would somehow change the mood... >>>> >>>> iMac:~ vosabristol$ cabal --version >>>> cabal-install version 1.16.0.2 >>>> using version 1.16.0 of the Cabal library >>>> >>>> iMac:~ vosabristol$ which cabal >>>> /usr/bin/cabal >>>> >>>> So... there is a possible case for *once again* performing a complete >>>> and utter removal of Haskell and its partners in crime and doing a fresh >>>> installation? >>>> >>>> >>>> Out of frustration I built OCaml and OPAM from sources last night but >>>> I'd still like to go with GHC! >>>> >>>> :) >>>> >>>> >>>> On 3 March 2015 at 20:43, Michael Snoyman wrote: >>>> >>>>> Funny that there's an issue being discussed in the cabal issue tracker >>>>> right now[1] similar to this. But the report you're giving here is >>>>> particularly strange. Cabal-1.16 implies that you're using GHC 7.6, which >>>>> is supported by the claim that base 4.7 isn't available. I'd recommend >>>>> starting off with running the following commands and pasting the output: >>>>> >>>>> ghc --version >>>>> which ghc >>>>> cabal --version >>>>> which cabal >>>>> >>>>> [1] https://github.com/haskell/cabal/issues/2438 >>>>> >>>>> On Tue, Mar 3, 2015 at 10:21 PM emacstheviking >>>>> wrote: >>>>> >>>>>> Forgot to add that somehow, despite the upgrade, my cabal version >>>>>> has gone backwards from 1.20.0.1 to 1.16.0 >>>>>> >>>>>> WTF? >>>>>> >>>>>> >>>>>> On 3 March 2015 at 20:19, emacstheviking wrote: >>>>>> >>>>>>> I started an OpenGL project within an LTS sandbox as guided on >>>>>>> another post and, somewhat foolishly it would see, I did a "cabal install >>>>>>> cabal-install" when prompted that a new version was available. >>>>>>> >>>>>>> The very next time I tried to work on my code.... I got this: >>>>>>> >>>>>>> bash-3.2$ pwd >>>>>>> /Users/seancharles/Documents/Coding/haskell/lts1 >>>>>>> bash-3.2$ cabal build >>>>>>> cabal: You need to re-run the 'configure' command. The version of >>>>>>> Cabal being >>>>>>> used has changed (was Cabal-1.20.0.1, now Cabal-1.16.0). >>>>>>> bash-3.2$ cabal configure >>>>>>> Resolving dependencies... >>>>>>> Configuring lts1-0.1.0.0... >>>>>>> cabal: At least the following dependencies are missing: >>>>>>> base ==4.7.* >>>>>>> bash-3.2$ cabal build >>>>>>> cabal: You need to re-run the 'configure' command. The version of >>>>>>> Cabal being >>>>>>> used has changed (was Cabal-1.20.0.1, now Cabal-1.16.0). >>>>>>> bash-3.2$ ls -l >>>>>>> total 112 >>>>>>> -rw-r--r-- 1 seancharles staff 19 Mar 2 12:53 LICENCSE >>>>>>> -rw-r--r-- 1 seancharles staff 552 Mar 3 20:09 Main.hs >>>>>>> -rw-r--r-- 1 seancharles staff 477 Mar 3 20:07 Main.hs~ >>>>>>> -rw-r--r-- 1 seancharles staff 46 Mar 2 12:52 Setup.hs >>>>>>> -rw-r--r-- 1 seancharles staff 30198 Mar 2 12:51 cabal.config >>>>>>> -rw-r--r-- 1 seancharles staff 1090 Mar 2 12:51 >>>>>>> cabal.sandbox.config >>>>>>> drwxr-xr-x 5 seancharles staff 170 Mar 2 12:53 dist >>>>>>> -rw-r--r-- 1 seancharles staff 1932 Mar 2 12:52 lts1.cabal >>>>>>> bash-3.2$ >>>>>>> >>>>>>> So, welcome to a different kind of hell, "cabal version hell" >>>>>>> perhaps? >>>>>>> >>>>>>> Can anybody help me get it running again? >>>>>>> Thanks. >>>>>>> Sean. >>>>>>> >>>>>>> >>>>>> _______________________________________________ >>>>>> Beginners mailing list >>>>>> Beginners at haskell.org >>>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>>>> >>>>> >>>>> _______________________________________________ >>>>> Beginners mailing list >>>>> Beginners at haskell.org >>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>>> >>>>> >>>> _______________________________________________ >>>> Beginners mailing list >>>> Beginners at haskell.org >>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>> >>> >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >>> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From objitsu at gmail.com Wed Mar 4 11:24:57 2015 From: objitsu at gmail.com (emacstheviking) Date: Wed, 4 Mar 2015 11:24:57 +0000 Subject: [Haskell-beginners] LTS is good but... In-Reply-To: References: Message-ID: Well, I have port installed 7.8.3 as it needs an existing GHC, then I unpacked 7.8.4 from tarball and............... checking whether bootstrap compiler is affected by bug 9439... You are using a new version of LLVM that hasn't been tested yet! We will try though... /var/folders/15/fqzwrj1n32gfgx8yy5t8v1bc0000gq/T/ghc7339_0/ghc7339_6.s:3:2: error: unknown directive .macosx_version_min 10, 0 ^ : Error running clang! you need clang installed to use theLLVM backend (or GHC tried to execute clang incorrectly) failed to compile Is that a problem??? It seems to have run the configure script just fine for all of that. On 4 March 2015 at 10:45, emacstheviking wrote: > I am a 30+ years hacker Boris, building from source might just tempt me > still!! HAHAHA > My machine is now "clean" so I will decide how to play it! > > Thanks again everybody. > > > On 4 March 2015 at 09:31, Boris wrote: > >> Hey, >> >> Little addition to what Michael already sent you. >> >> To get ?the latest? you should build from sources :D >> >> But in case it?s ok for you to have ghc 7.8.3 and you don?t want to ./configure; >> make; make install, you might also check this installation script on >> github . >> >> >> >> On March 4, 2015 at 11:28:50, Michael Snoyman (michael at snoyman.com) >> wrote: >> >> I'd recommend looking at: >> >> http://www.stackage.org/install#mac-os-x >> https://github.com/bitemyapp/learnhaskell/blob/master/README.md#mac-os-x >> >> I don't generally recommend using the platform installer, it ends up >> pegging libraries to old versions which causes dependency problems, or in >> some cases have known bugs. >> >> On Wed, Mar 4, 2015 at 11:26 AM emacstheviking wrote: >> >>> Agreed Michael! >>> >>> I am currently wiping all Mac Ports packages and I will perform a clean >>> up of /Library/Haskell etc. >>> >>> What is the *preferred* way to get the lastest for OSX: Using homebrew, >>> macports or the Haskell Platform. I *used* to use the platform installer >>> but for some reason (cabal I expect!) I started trying out other ways... >>> >>> I think actually I will go the platform packager again... >>> >>> On 4 March 2015 at 09:13, Michael Snoyman wrote: >>> >>>> I can't really explain the details of what's going on here. It seems >>>> that in some cases different versions of the executables are being found, >>>> but I don't know why. Wiping out your sandbox (cabal sandbox delete) and >>>> starting over may be sufficient to recover. >>>> >>>> On Wed, Mar 4, 2015 at 11:11 AM emacstheviking >>>> wrote: >>>> >>>>> As requested, >>>>> >>>>> iMac:~ vosabristol$ ghc --version >>>>> The Glorious Glasgow Haskell Compilation System, version 7.8.3 >>>>> >>>>> which ghc >>>>> /opt/local/bin/ghc >>>>> >>>>> Hmm.... it shows a macports instsallation of GHC... but I am sure >>>>> that's how I git it... I *used* to use the OSX installation package but I >>>>> thought a clean start using MacPorts would somehow change the mood... >>>>> >>>>> iMac:~ vosabristol$ cabal --version >>>>> cabal-install version 1.16.0.2 >>>>> using version 1.16.0 of the Cabal library >>>>> >>>>> iMac:~ vosabristol$ which cabal >>>>> /usr/bin/cabal >>>>> >>>>> So... there is a possible case for *once again* performing a complete >>>>> and utter removal of Haskell and its partners in crime and doing a fresh >>>>> installation? >>>>> >>>>> >>>>> Out of frustration I built OCaml and OPAM from sources last night but >>>>> I'd still like to go with GHC! >>>>> >>>>> :) >>>>> >>>>> >>>>> On 3 March 2015 at 20:43, Michael Snoyman wrote: >>>>> >>>>>> Funny that there's an issue being discussed in the cabal issue >>>>>> tracker right now[1] similar to this. But the report you're giving >>>>>> here is particularly strange. Cabal-1.16 implies that you're using GHC 7.6, >>>>>> which is supported by the claim that base 4.7 isn't available. I'd >>>>>> recommend starting off with running the following commands and pasting the >>>>>> output: >>>>>> >>>>>> ghc --version >>>>>> which ghc >>>>>> cabal --version >>>>>> which cabal >>>>>> >>>>>> [1] https://github.com/haskell/cabal/issues/2438 >>>>>> >>>>>> On Tue, Mar 3, 2015 at 10:21 PM emacstheviking >>>>>> wrote: >>>>>> >>>>>>> Forgot to add that somehow, despite the upgrade, my cabal version >>>>>>> has gone backwards from 1.20.0.1 to 1.16.0 >>>>>>> >>>>>>> WTF? >>>>>>> >>>>>>> >>>>>>> On 3 March 2015 at 20:19, emacstheviking wrote: >>>>>>> >>>>>>>> I started an OpenGL project within an LTS sandbox as guided on >>>>>>>> another post and, somewhat foolishly it would see, I did a "cabal install >>>>>>>> cabal-install" when prompted that a new version was available. >>>>>>>> >>>>>>>> The very next time I tried to work on my code.... I got this: >>>>>>>> >>>>>>>> bash-3.2$ pwd >>>>>>>> /Users/seancharles/Documents/Coding/haskell/lts1 >>>>>>>> bash-3.2$ cabal build >>>>>>>> cabal: You need to re-run the 'configure' command. The version of >>>>>>>> Cabal being >>>>>>>> used has changed (was Cabal-1.20.0.1, now Cabal-1.16.0). >>>>>>>> bash-3.2$ cabal configure >>>>>>>> Resolving dependencies... >>>>>>>> Configuring lts1-0.1.0.0... >>>>>>>> cabal: At least the following dependencies are missing: >>>>>>>> base ==4.7.* >>>>>>>> bash-3.2$ cabal build >>>>>>>> cabal: You need to re-run the 'configure' command. The version of >>>>>>>> Cabal being >>>>>>>> used has changed (was Cabal-1.20.0.1, now Cabal-1.16.0). >>>>>>>> bash-3.2$ ls -l >>>>>>>> total 112 >>>>>>>> -rw-r--r-- 1 seancharles staff 19 Mar 2 12:53 LICENCSE >>>>>>>> -rw-r--r-- 1 seancharles staff 552 Mar 3 20:09 Main.hs >>>>>>>> -rw-r--r-- 1 seancharles staff 477 Mar 3 20:07 Main.hs~ >>>>>>>> -rw-r--r-- 1 seancharles staff 46 Mar 2 12:52 Setup.hs >>>>>>>> -rw-r--r-- 1 seancharles staff 30198 Mar 2 12:51 cabal.config >>>>>>>> -rw-r--r-- 1 seancharles staff 1090 Mar 2 12:51 >>>>>>>> cabal.sandbox.config >>>>>>>> drwxr-xr-x 5 seancharles staff 170 Mar 2 12:53 dist >>>>>>>> -rw-r--r-- 1 seancharles staff 1932 Mar 2 12:52 lts1.cabal >>>>>>>> bash-3.2$ >>>>>>>> >>>>>>>> So, welcome to a different kind of hell, "cabal version hell" >>>>>>>> perhaps? >>>>>>>> >>>>>>>> Can anybody help me get it running again? >>>>>>>> Thanks. >>>>>>>> Sean. >>>>>>>> >>>>>>>> >>>>>>> _______________________________________________ >>>>>>> Beginners mailing list >>>>>>> Beginners at haskell.org >>>>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>>>>> >>>>>> >>>>>> _______________________________________________ >>>>>> Beginners mailing list >>>>>> Beginners at haskell.org >>>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>>>> >>>>>> >>>>> _______________________________________________ >>>>> Beginners mailing list >>>>> Beginners at haskell.org >>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>>> >>>> >>>> _______________________________________________ >>>> Beginners mailing list >>>> Beginners at haskell.org >>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>> >>>> >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From objitsu at gmail.com Wed Mar 4 11:25:28 2015 From: objitsu at gmail.com (emacstheviking) Date: Wed, 4 Mar 2015 11:25:28 +0000 Subject: [Haskell-beginners] LTS is good but... In-Reply-To: References: Message-ID: Forgot this: ---------------------------------------------------------------------- Configure completed successfully. Building GHC version : 7.8.4 Build platform : x86_64-apple-darwin Host platform : x86_64-apple-darwin Target platform : x86_64-apple-darwin Bootstrapping using : /opt/local/bin/ghc which is version : 7.8.3 Using clang : /usr/bin/gcc which is version : 6.0 Building a cross compiler : NO cpp : /usr/bin/gcc cpp-flags : -E -undef -traditional -Wno-invalid-pp-token -Wno-unicode -Wno-trigraphs ld : /opt/local/bin/ld Happy : () Alex : () Perl : /opt/local/bin/perl dblatex : xsltproc : /opt/local/bin/xsltproc Using LLVM tools llc : opt : HsColour : /opt/local/bin/HsColour Building DocBook HTML documentation : YES Building DocBook PS documentation : NO Building DocBook PDF documentation : NO ---------------------------------------------------------------------- On 4 March 2015 at 11:24, emacstheviking wrote: > Well, I have port installed 7.8.3 as it needs an existing GHC, then I > unpacked 7.8.4 from tarball and............... > > checking whether bootstrap compiler is affected by bug 9439... You are > using a new version of LLVM that hasn't been tested yet! > We will try though... > > /var/folders/15/fqzwrj1n32gfgx8yy5t8v1bc0000gq/T/ghc7339_0/ghc7339_6.s:3:2: > error: unknown directive > .macosx_version_min 10, 0 > ^ > > : > Error running clang! you need clang installed to use theLLVM backend > (or GHC tried to execute clang incorrectly) > failed to compile > > Is that a problem??? It seems to have run the configure script just fine > for all of that. > > > On 4 March 2015 at 10:45, emacstheviking wrote: > >> I am a 30+ years hacker Boris, building from source might just tempt me >> still!! HAHAHA >> My machine is now "clean" so I will decide how to play it! >> >> Thanks again everybody. >> >> >> On 4 March 2015 at 09:31, Boris wrote: >> >>> Hey, >>> >>> Little addition to what Michael already sent you. >>> >>> To get ?the latest? you should build from sources :D >>> >>> But in case it?s ok for you to have ghc 7.8.3 and you don?t want to ./configure; >>> make; make install, you might also check this installation script on >>> github . >>> >>> >>> >>> On March 4, 2015 at 11:28:50, Michael Snoyman (michael at snoyman.com) >>> wrote: >>> >>> I'd recommend looking at: >>> >>> http://www.stackage.org/install#mac-os-x >>> https://github.com/bitemyapp/learnhaskell/blob/master/README.md#mac-os-x >>> >>> I don't generally recommend using the platform installer, it ends up >>> pegging libraries to old versions which causes dependency problems, or in >>> some cases have known bugs. >>> >>> On Wed, Mar 4, 2015 at 11:26 AM emacstheviking >>> wrote: >>> >>>> Agreed Michael! >>>> >>>> I am currently wiping all Mac Ports packages and I will perform a clean >>>> up of /Library/Haskell etc. >>>> >>>> What is the *preferred* way to get the lastest for OSX: Using homebrew, >>>> macports or the Haskell Platform. I *used* to use the platform installer >>>> but for some reason (cabal I expect!) I started trying out other ways... >>>> >>>> I think actually I will go the platform packager again... >>>> >>>> On 4 March 2015 at 09:13, Michael Snoyman wrote: >>>> >>>>> I can't really explain the details of what's going on here. It seems >>>>> that in some cases different versions of the executables are being found, >>>>> but I don't know why. Wiping out your sandbox (cabal sandbox delete) and >>>>> starting over may be sufficient to recover. >>>>> >>>>> On Wed, Mar 4, 2015 at 11:11 AM emacstheviking >>>>> wrote: >>>>> >>>>>> As requested, >>>>>> >>>>>> iMac:~ vosabristol$ ghc --version >>>>>> The Glorious Glasgow Haskell Compilation System, version 7.8.3 >>>>>> >>>>>> which ghc >>>>>> /opt/local/bin/ghc >>>>>> >>>>>> Hmm.... it shows a macports instsallation of GHC... but I am sure >>>>>> that's how I git it... I *used* to use the OSX installation package but I >>>>>> thought a clean start using MacPorts would somehow change the mood... >>>>>> >>>>>> iMac:~ vosabristol$ cabal --version >>>>>> cabal-install version 1.16.0.2 >>>>>> using version 1.16.0 of the Cabal library >>>>>> >>>>>> iMac:~ vosabristol$ which cabal >>>>>> /usr/bin/cabal >>>>>> >>>>>> So... there is a possible case for *once again* performing a complete >>>>>> and utter removal of Haskell and its partners in crime and doing a fresh >>>>>> installation? >>>>>> >>>>>> >>>>>> Out of frustration I built OCaml and OPAM from sources last night but >>>>>> I'd still like to go with GHC! >>>>>> >>>>>> :) >>>>>> >>>>>> >>>>>> On 3 March 2015 at 20:43, Michael Snoyman >>>>>> wrote: >>>>>> >>>>>>> Funny that there's an issue being discussed in the cabal issue >>>>>>> tracker right now[1] similar to this. But the report you're giving >>>>>>> here is particularly strange. Cabal-1.16 implies that you're using GHC 7.6, >>>>>>> which is supported by the claim that base 4.7 isn't available. I'd >>>>>>> recommend starting off with running the following commands and pasting the >>>>>>> output: >>>>>>> >>>>>>> ghc --version >>>>>>> which ghc >>>>>>> cabal --version >>>>>>> which cabal >>>>>>> >>>>>>> [1] https://github.com/haskell/cabal/issues/2438 >>>>>>> >>>>>>> On Tue, Mar 3, 2015 at 10:21 PM emacstheviking >>>>>>> wrote: >>>>>>> >>>>>>>> Forgot to add that somehow, despite the upgrade, my cabal version >>>>>>>> has gone backwards from 1.20.0.1 to 1.16.0 >>>>>>>> >>>>>>>> WTF? >>>>>>>> >>>>>>>> >>>>>>>> On 3 March 2015 at 20:19, emacstheviking wrote: >>>>>>>> >>>>>>>>> I started an OpenGL project within an LTS sandbox as guided on >>>>>>>>> another post and, somewhat foolishly it would see, I did a "cabal install >>>>>>>>> cabal-install" when prompted that a new version was available. >>>>>>>>> >>>>>>>>> The very next time I tried to work on my code.... I got this: >>>>>>>>> >>>>>>>>> bash-3.2$ pwd >>>>>>>>> /Users/seancharles/Documents/Coding/haskell/lts1 >>>>>>>>> bash-3.2$ cabal build >>>>>>>>> cabal: You need to re-run the 'configure' command. The version of >>>>>>>>> Cabal being >>>>>>>>> used has changed (was Cabal-1.20.0.1, now Cabal-1.16.0). >>>>>>>>> bash-3.2$ cabal configure >>>>>>>>> Resolving dependencies... >>>>>>>>> Configuring lts1-0.1.0.0... >>>>>>>>> cabal: At least the following dependencies are missing: >>>>>>>>> base ==4.7.* >>>>>>>>> bash-3.2$ cabal build >>>>>>>>> cabal: You need to re-run the 'configure' command. The version of >>>>>>>>> Cabal being >>>>>>>>> used has changed (was Cabal-1.20.0.1, now Cabal-1.16.0). >>>>>>>>> bash-3.2$ ls -l >>>>>>>>> total 112 >>>>>>>>> -rw-r--r-- 1 seancharles staff 19 Mar 2 12:53 LICENCSE >>>>>>>>> -rw-r--r-- 1 seancharles staff 552 Mar 3 20:09 Main.hs >>>>>>>>> -rw-r--r-- 1 seancharles staff 477 Mar 3 20:07 Main.hs~ >>>>>>>>> -rw-r--r-- 1 seancharles staff 46 Mar 2 12:52 Setup.hs >>>>>>>>> -rw-r--r-- 1 seancharles staff 30198 Mar 2 12:51 cabal.config >>>>>>>>> -rw-r--r-- 1 seancharles staff 1090 Mar 2 12:51 >>>>>>>>> cabal.sandbox.config >>>>>>>>> drwxr-xr-x 5 seancharles staff 170 Mar 2 12:53 dist >>>>>>>>> -rw-r--r-- 1 seancharles staff 1932 Mar 2 12:52 lts1.cabal >>>>>>>>> bash-3.2$ >>>>>>>>> >>>>>>>>> So, welcome to a different kind of hell, "cabal version hell" >>>>>>>>> perhaps? >>>>>>>>> >>>>>>>>> Can anybody help me get it running again? >>>>>>>>> Thanks. >>>>>>>>> Sean. >>>>>>>>> >>>>>>>>> >>>>>>>> _______________________________________________ >>>>>>>> Beginners mailing list >>>>>>>> Beginners at haskell.org >>>>>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>>>>>> >>>>>>> >>>>>>> _______________________________________________ >>>>>>> Beginners mailing list >>>>>>> Beginners at haskell.org >>>>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>>>>> >>>>>>> >>>>>> _______________________________________________ >>>>>> Beginners mailing list >>>>>> Beginners at haskell.org >>>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>>>> >>>>> >>>>> _______________________________________________ >>>>> Beginners mailing list >>>>> Beginners at haskell.org >>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>>> >>>>> >>>> _______________________________________________ >>>> Beginners mailing list >>>> Beginners at haskell.org >>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>> >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >>> >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >>> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From d12frosted at icloud.com Wed Mar 4 11:28:37 2015 From: d12frosted at icloud.com (Boris) Date: Wed, 04 Mar 2015 13:28:37 +0200 Subject: [Haskell-beginners] LTS is good but... In-Reply-To: References: Message-ID: Have you installed xcode command-line tools? And what which clang returns? On March 4, 2015 at 13:26:14, emacstheviking (objitsu at gmail.com) wrote: Forgot this: ---------------------------------------------------------------------- Configure completed successfully. ? ?Building GHC version ?: 7.8.4 ? ?Build platform ? ? ? ?: x86_64-apple-darwin ? ?Host platform ? ? ? ? : x86_64-apple-darwin ? ?Target platform ? ? ? : x86_64-apple-darwin ? ?Bootstrapping using ? : /opt/local/bin/ghc ? ? ? which is version ? : 7.8.3 ? ?Using clang ? ? ? ? ? ? ? : /usr/bin/gcc ? ? ? which is version ? ? ? : 6.0 ? ?Building a cross compiler : NO ? ?cpp ? ? ? : /usr/bin/gcc ? ?cpp-flags : -E -undef -traditional -Wno-invalid-pp-token -Wno-unicode -Wno-trigraphs ? ?ld ? ? ? ?: /opt/local/bin/ld ? ?Happy ? ? : ?() ? ?Alex ? ? ?: ?() ? ?Perl ? ? ?: /opt/local/bin/perl ? ?dblatex ? : ? ?xsltproc ?: /opt/local/bin/xsltproc ? ?Using LLVM tools ? ? ? llc ? : ? ? ? opt ? : ? ?HsColour : /opt/local/bin/HsColour ? ?Building DocBook HTML documentation : YES ? ?Building DocBook PS documentation ? : NO ? ?Building DocBook PDF documentation ?: NO ---------------------------------------------------------------------- On 4 March 2015 at 11:24, emacstheviking wrote: Well, I have port installed 7.8.3 as it needs an existing GHC, then I unpacked 7.8.4 from tarball and............... checking whether bootstrap compiler is affected by bug 9439... You are using a new version of LLVM that hasn't been tested yet! We will try though... /var/folders/15/fqzwrj1n32gfgx8yy5t8v1bc0000gq/T/ghc7339_0/ghc7339_6.s:3:2: ? ? ?error: unknown directive ? ? ? ? ? ? .macosx_version_min 10, 0 ? ? ? ? ? ? ^ : ? ? Error running clang! you need clang installed to use theLLVM backend ? ? (or GHC tried to execute clang incorrectly) failed to compile Is that a problem??? It seems to have run the configure script just fine for all of that. On 4 March 2015 at 10:45, emacstheviking wrote: I am a 30+ years hacker Boris, building from source might just tempt me still!! HAHAHA My machine is now "clean" so I will decide how to play it! Thanks again everybody. On 4 March 2015 at 09:31, Boris wrote: Hey, Little addition to what Michael already sent you. To get ?the latest? you should build from sources :D But in case it?s ok for you to have ghc 7.8.3 and you don?t want to ./configure; make; make install, you might also check this installation script on github. On March 4, 2015 at 11:28:50, Michael Snoyman (michael at snoyman.com) wrote: I'd recommend looking at: http://www.stackage.org/install#mac-os-x https://github.com/bitemyapp/learnhaskell/blob/master/README.md#mac-os-x I don't generally recommend using the platform installer, it ends up pegging libraries to old versions which causes dependency problems, or in some cases have known bugs. On Wed, Mar 4, 2015 at 11:26 AM emacstheviking wrote: Agreed Michael! I am currently wiping all Mac Ports packages and I will perform a clean up of /Library/Haskell etc. What is the *preferred* way to get the lastest for OSX: Using homebrew, macports or the Haskell Platform. I *used* to use the platform installer but for some reason (cabal I expect!) I started trying out other ways... I think actually I will go the platform packager again... On 4 March 2015 at 09:13, Michael Snoyman wrote: I can't really explain the details of what's going on here. It seems that in some cases different versions of the executables are being found, but I don't know why. Wiping out your sandbox (cabal sandbox delete) and starting over may be sufficient to recover. On Wed, Mar 4, 2015 at 11:11 AM emacstheviking wrote: As requested, iMac:~ vosabristol$ ghc --version The Glorious Glasgow Haskell Compilation System, version 7.8.3 which ghc /opt/local/bin/ghc Hmm.... it shows a macports instsallation of GHC... but I am sure that's how I git it... I *used* to use the OSX installation package but I thought a clean start using MacPorts would somehow change the mood... iMac:~ vosabristol$ cabal --version cabal-install version 1.16.0.2 using version 1.16.0 of the Cabal library iMac:~ vosabristol$ which cabal /usr/bin/cabal So... there is a possible case for *once again* performing a complete and utter removal of Haskell and its partners in crime and doing a fresh installation? Out of frustration I built OCaml and OPAM from sources last night but I'd still like to go with GHC! :) On 3 March 2015 at 20:43, Michael Snoyman wrote: Funny that there's an issue being discussed in the cabal issue tracker right now[1] similar to this.?But the report you're giving here is particularly strange. Cabal-1.16 implies that you're using GHC 7.6, which is supported by the claim that base 4.7 isn't available. I'd recommend starting off with running the following commands and pasting the output: ghc --version which ghc cabal --version which cabal [1]?https://github.com/haskell/cabal/issues/2438 On Tue, Mar 3, 2015 at 10:21 PM emacstheviking wrote: Forgot to add that somehow, despite the upgrade, my cabal version has gone backwards from 1.20.0.1 to 1.16.0 WTF? On 3 March 2015 at 20:19, emacstheviking wrote: I started an OpenGL project within an LTS sandbox as guided on another post and, somewhat foolishly it would see, I did a "cabal install cabal-install" when prompted that a new version was available. The very next time I tried to work on my code.... I got this: bash-3.2$ pwd /Users/seancharles/Documents/Coding/haskell/lts1 bash-3.2$ cabal build cabal: You need to re-run the 'configure' command. The version of Cabal being used has changed (was Cabal-1.20.0.1, now Cabal-1.16.0). bash-3.2$ cabal configure Resolving dependencies... Configuring lts1-0.1.0.0... cabal: At least the following dependencies are missing: base ==4.7.* bash-3.2$ cabal build cabal: You need to re-run the 'configure' command. The version of Cabal being used has changed (was Cabal-1.20.0.1, now Cabal-1.16.0). bash-3.2$ ls -l total 112 -rw-r--r-- ?1 seancharles ?staff ? ? 19 Mar ?2 12:53 LICENCSE -rw-r--r-- ?1 seancharles ?staff ? ?552 Mar ?3 20:09 Main.hs -rw-r--r-- ?1 seancharles ?staff ? ?477 Mar ?3 20:07 Main.hs~ -rw-r--r-- ?1 seancharles ?staff ? ? 46 Mar ?2 12:52 Setup.hs -rw-r--r-- ?1 seancharles ?staff ?30198 Mar ?2 12:51 cabal.config -rw-r--r-- ?1 seancharles ?staff ? 1090 Mar ?2 12:51 cabal.sandbox.config drwxr-xr-x ?5 seancharles ?staff ? ?170 Mar ?2 12:53 dist -rw-r--r-- ?1 seancharles ?staff ? 1932 Mar ?2 12:52 lts1.cabal bash-3.2$? So, welcome to a different kind of hell, "cabal version hell" perhaps? Can anybody help me get it running again? Thanks. Sean. _______________________________________________ Beginners mailing list Beginners at haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners _______________________________________________ Beginners mailing list Beginners at haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners _______________________________________________ Beginners mailing list Beginners at haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners _______________________________________________ Beginners mailing list Beginners at haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners _______________________________________________ Beginners mailing list Beginners at haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners _______________________________________________ Beginners mailing list Beginners at haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners _______________________________________________ Beginners mailing list Beginners at haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners _______________________________________________ Beginners mailing list Beginners at haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: From ky3 at atamo.com Wed Mar 4 12:10:49 2015 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Wed, 4 Mar 2015 19:10:49 +0700 Subject: [Haskell-beginners] Alfred Programs in Haskell In-Reply-To: <54F69A50.4030308@customct.com> References: <54F69A50.4030308@customct.com> Message-ID: On Wed, Mar 4, 2015 at 12:38 PM, Richard Guay wrote: > fExist <- doesFileExist $ h ++ cacheDirBasic ++ getBundleID ++ "/" ++ > fileName > if fExist > then do > contents <- readFile $ h ++ cacheDirBasic ++ getBundleID ++ "/" ++ > fileName > First of all, let's refactor that into a let binding, e.g. let pathName = h ++ cacheDirBasic ++ getBundleID ++ "/" ++ fileName fExist <- doesFileExist pathName if fExist then readFile pathName else return "" The advantage of keeping DRY here should be obvious. Defining the same thing in 2 places can lead to both getting out of lockstep. Now as for debugging the actual problem, have you tried the REPL? That is, launch ghci, load the appropriate libraries, and see what happens when you enter doesFileExist "/home/me/myfile" and similarly for readFile. That way you'd rule things out like a file permissions problem, etc. -- Kim-Ee -------------- next part -------------- An HTML attachment was scrubbed... URL: From objitsu at gmail.com Wed Mar 4 12:51:43 2015 From: objitsu at gmail.com (emacstheviking) Date: Wed, 4 Mar 2015 12:51:43 +0000 Subject: [Haskell-beginners] GHC 7.8.4 source build fails on OSX... Message-ID: ld: couldn't dlopen() /usr/lib/libdtrace.dylib: dlopen(/usr/lib/libdtrace.dylib, 1): Symbol not found: _CGLGetCurrentContext Referenced from: /System/Library/Frameworks/CoreVideo.framework/Versions/A/CoreVideo Expected in: /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL in /System/Library/Frameworks/CoreVideo.framework/Versions/A/CoreVideo for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make[1]: *** [rts/dist/build/libHSrts-ghc7.8.4.dylib] Error 1 make: *** [all] Error 2 iMac:ghc-7.8.4 vosabristol$ Perhaps I need to tweak the configure parameters and try again... stackoverflow has this page: http://stackoverflow.com/questions/19480099/compiling-macos-application-with-cgl There is no CGL framework in OS X (CGL is included in the OpenGL framework, you need only #include OpenGL/OpenGL.h), and you do not use -lXXX to link against a framework either. Now, depending on how your Makefile is structured, you may also have a property known as LD_FLAGS for a separate linking stage - you *also* need to include -framework OpenGL there. This directive does *both*, include path resolution and linker path resolution for frameworks. ? Andon M. Coleman Oct 20 '13 at 19:36 -------------- next part -------------- An HTML attachment was scrubbed... URL: From raguay at customct.com Wed Mar 4 14:01:36 2015 From: raguay at customct.com (Richard Guay) Date: Wed, 04 Mar 2015 21:01:36 +0700 Subject: [Haskell-beginners] Alfred Programs in Haskell In-Reply-To: References: <54F69A50.4030308@customct.com> Message-ID: <54F71040.40609@customct.com> It's not a file permission problem because it works great when the file exists. But, when the file doesn't exist, it still tries to read the file. It acts like the file is there when it isn't. In ghci, it returns the true boolean when the file is there and a false when it isn't. But, in the program, it is always executing the readFile. Kim-Ee Yeoh wrote: > > > On Wed, Mar 4, 2015 at 12:38 PM, Richard Guay > wrote: > > fExist <- doesFileExist $ h ++ cacheDirBasic ++ getBundleID ++ > "/" ++ fileName > if fExist > then do > contents <- readFile $ h ++ cacheDirBasic ++ getBundleID > ++ "/" ++ fileName > > > First of all, let's refactor that into a let binding, e.g. > > let pathName = h ++ cacheDirBasic ++ getBundleID ++ "/" ++ fileName > fExist <- doesFileExist pathName > if fExist then readFile pathName else return "" > > The advantage of keeping DRY here should be obvious. Defining the same > thing in 2 places can lead to both getting out of lockstep. > > Now as for debugging the actual problem, have you tried the REPL? That > is, launch ghci, load the appropriate libraries, and see what happens > when you enter > > doesFileExist "/home/me/myfile" > > and similarly for readFile. That way you'd rule things out like a file > permissions problem, etc. > > > -- Kim-Ee > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: From objitsu at gmail.com Wed Mar 4 14:05:24 2015 From: objitsu at gmail.com (emacstheviking) Date: Wed, 4 Mar 2015 14:05:24 +0000 Subject: [Haskell-beginners] GHC 7.8.4 source build fails on OSX... In-Reply-To: References: Message-ID: tried adding: LIBS="-framework OpenGL" ./configure same result.... bummer. On 4 March 2015 at 12:51, emacstheviking wrote: > > ld: couldn't dlopen() /usr/lib/libdtrace.dylib: > dlopen(/usr/lib/libdtrace.dylib, 1): Symbol not found: _CGLGetCurrentContext > Referenced from: > /System/Library/Frameworks/CoreVideo.framework/Versions/A/CoreVideo > Expected in: > /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL > in /System/Library/Frameworks/CoreVideo.framework/Versions/A/CoreVideo > for architecture x86_64 > clang: error: linker command failed with exit code 1 (use -v to see > invocation) > make[1]: *** [rts/dist/build/libHSrts-ghc7.8.4.dylib] Error 1 > make: *** [all] Error 2 > iMac:ghc-7.8.4 vosabristol$ > > Perhaps I need to tweak the configure parameters and try again... > stackoverflow has this page: > > http://stackoverflow.com/questions/19480099/compiling-macos-application-with-cgl > > There is no CGL framework in OS X (CGL is included in the OpenGL > framework, you need only #include OpenGL/OpenGL.h), and you do not use > -lXXX to link against a framework either. Now, depending on how your > Makefile is structured, you may also have a property known as LD_FLAGS for > a separate linking stage - you *also* need to include -framework OpenGL there. > This directive does *both*, include path resolution and linker path > resolution for frameworks. ? Andon M. Coleman > Oct 20 '13 at > 19:36 > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From objitsu at gmail.com Wed Mar 4 14:12:44 2015 From: objitsu at gmail.com (emacstheviking) Date: Wed, 4 Mar 2015 14:12:44 +0000 Subject: [Haskell-beginners] GHC 7.8.4 source build fails on OSX... In-Reply-To: References: Message-ID: The Gods provided me with serendipity; https://ghcformacosx.github.io/ JOB DONE, FLAWLESS! Many thanks to those concerned! :) On 4 March 2015 at 14:05, emacstheviking wrote: > tried adding: > > LIBS="-framework OpenGL" ./configure > > same result.... bummer. > > On 4 March 2015 at 12:51, emacstheviking wrote: > >> >> ld: couldn't dlopen() /usr/lib/libdtrace.dylib: >> dlopen(/usr/lib/libdtrace.dylib, 1): Symbol not found: _CGLGetCurrentContext >> Referenced from: >> /System/Library/Frameworks/CoreVideo.framework/Versions/A/CoreVideo >> Expected in: >> /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL >> in /System/Library/Frameworks/CoreVideo.framework/Versions/A/CoreVideo >> for architecture x86_64 >> clang: error: linker command failed with exit code 1 (use -v to see >> invocation) >> make[1]: *** [rts/dist/build/libHSrts-ghc7.8.4.dylib] Error 1 >> make: *** [all] Error 2 >> iMac:ghc-7.8.4 vosabristol$ >> >> Perhaps I need to tweak the configure parameters and try again... >> stackoverflow has this page: >> >> http://stackoverflow.com/questions/19480099/compiling-macos-application-with-cgl >> >> There is no CGL framework in OS X (CGL is included in the OpenGL >> framework, you need only #include OpenGL/OpenGL.h), and you do not use >> -lXXX to link against a framework either. Now, depending on how your >> Makefile is structured, you may also have a property known as LD_FLAGS for >> a separate linking stage - you *also* need to include -framework OpenGL there. >> This directive does *both*, include path resolution and linker path >> resolution for frameworks. ? Andon M. Coleman >> Oct 20 '13 at >> 19:36 >> >> >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From d12frosted at icloud.com Wed Mar 4 14:18:45 2015 From: d12frosted at icloud.com (Boris) Date: Wed, 04 Mar 2015 16:18:45 +0200 Subject: [Haskell-beginners] GHC 7.8.4 source build fails on OSX... In-Reply-To: References: Message-ID: Yeah, one might call Michael Snoyman god :D Writing this because it is Michael who provided you this link On March 4, 2015 at 11:28:50, Michael Snoyman (michael at snoyman.com) wrote: I'd recommend looking at: http://www.stackage.org/install#mac-os-x https://github.com/bitemyapp/learnhaskell/blob/master/README.md#mac-os-x I don't generally recommend using the platform installer, it ends up pegging libraries to old versions which causes dependency problems, or in some cases have known bugs. On March 4, 2015 at 16:13:43, emacstheviking (objitsu at gmail.com) wrote: The Gods provided me with serendipity; https://ghcformacosx.github.io/ JOB DONE, FLAWLESS! Many thanks to those concerned! :) On 4 March 2015 at 14:05, emacstheviking wrote: tried adding: LIBS="-framework OpenGL" ./configure same result.... bummer. On 4 March 2015 at 12:51, emacstheviking wrote: ld: couldn't dlopen() /usr/lib/libdtrace.dylib: dlopen(/usr/lib/libdtrace.dylib, 1): Symbol not found: _CGLGetCurrentContext ? Referenced from: /System/Library/Frameworks/CoreVideo.framework/Versions/A/CoreVideo ? Expected in: /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL ?in /System/Library/Frameworks/CoreVideo.framework/Versions/A/CoreVideo for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make[1]: *** [rts/dist/build/libHSrts-ghc7.8.4.dylib] Error 1 make: *** [all] Error 2 iMac:ghc-7.8.4 vosabristol$ Perhaps I need to tweak the configure parameters and try again... stackoverflow has this page: http://stackoverflow.com/questions/19480099/compiling-macos-application-with-cgl There is no CGL framework in OS X (CGL is included in the OpenGL framework, you need only?#include OpenGL/OpenGL.h), and you do not use?-lXXX?to link against a framework either. Now, depending on how your Makefile is structured, you may also have a property known as LD_FLAGS for a separate linking stage - you?also?need to include?-framework OpenGL?there. This directive does?both, include path resolution and linker path resolution for frameworks.????Andon M. Coleman?Oct 20 '13 at 19:36? _______________________________________________ Beginners mailing list Beginners at haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: From allbery.b at gmail.com Wed Mar 4 14:32:50 2015 From: allbery.b at gmail.com (Brandon Allbery) Date: Wed, 4 Mar 2015 09:32:50 -0500 Subject: [Haskell-beginners] LTS is good but... In-Reply-To: References: Message-ID: On Wed, Mar 4, 2015 at 4:25 AM, emacstheviking wrote: > What is the *preferred* way to get the lastest for OSX: Using homebrew, > macports or the Haskell Platform. I *used* to use the platform installer > but for some reason (cabal I expect!) I started trying out other ways... Depends on who you ask. I use MacPorts and keep it updated, but please-root-me (aka Homebrew) is preferred by most people these days. You will find people arguing that you should use the Platform and people who insist you should always install just ghc and cabal, or people who insist you shouldn't ever look beyond Stackage (great if Stackage bothers to acknowledge that the library you need exists). -- brandon s allbery kf8nh sine nomine associates allbery.b at gmail.com ballbery at sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From thbach at students.uni-mainz.de Wed Mar 4 14:43:12 2015 From: thbach at students.uni-mainz.de (Thomas Bach) Date: Wed, 4 Mar 2015 15:43:12 +0100 Subject: [Haskell-beginners] Alfred Programs in Haskell In-Reply-To: <54F71040.40609@customct.com> (Richard Guay's message of "Wed, 4 Mar 2015 21:01:36 +0700") References: <54F69A50.4030308@customct.com> <54F71040.40609@customct.com> Message-ID: <87sidklt6n.fsf@ilxwinb01.fritz.box> Richard Guay writes: > It's not a file permission problem because it works great when the > file exists. But, when the file doesn't exist, it still tries to read > the file. Is this also the case with the version provided by Kim-Ee Yeoh? > It acts like the file is there when it isn't. In ghci, it returns the > true boolean when the file is there and a false when it isn't. But, in > the program, it is always executing the readFile. This is most unlikely a problem of ghc, i.e. I think there is some problem in your programs logic. Can you provide further code possibly restricting it to a minimal breaking example? Also: have you tried running the function in question in ghci? Regards Thomas. From michael at snoyman.com Wed Mar 4 15:31:02 2015 From: michael at snoyman.com (Michael Snoyman) Date: Wed, 04 Mar 2015 15:31:02 +0000 Subject: [Haskell-beginners] LTS is good but... References: Message-ID: On Wed, Mar 4, 2015 at 4:32 PM Brandon Allbery wrote: > On Wed, Mar 4, 2015 at 4:25 AM, emacstheviking wrote: > >> What is the *preferred* way to get the lastest for OSX: Using homebrew, >> macports or the Haskell Platform. I *used* to use the platform installer >> but for some reason (cabal I expect!) I started trying out other ways... > > > Depends on who you ask. I use MacPorts and keep it updated, but > please-root-me (aka Homebrew) is preferred by most people these days. You > will find people arguing that you should use the Platform and people who > insist you should always install just ghc and cabal, or people who insist > you shouldn't ever look beyond Stackage (great if Stackage bothers to > acknowledge that the library you need exists). > > > Just to clarify, because there seems to be some confusion in your comments on Stackage. When someone sets up a project to use Stackage[1], you still have full access to all packages on Hackage, there just isn't any way to be certain the packages will compile reliably (which is the case with installing from Hackage as well). And getting a package into Stackage is a simple, open procedure[2] which anyone is allowed to participate in. In other words: Stackage acknowledges the existence of every package on Hackage, and can provide build guarantees for any package that is added to its build-constraints file. [1] Minimal procedure: run `wget http://www.stackage.org/lts/cabal.config` [2] https://github.com/fpco/stackage#get-your-package-included -------------- next part -------------- An HTML attachment was scrubbed... URL: From raguay at customct.com Wed Mar 4 15:36:01 2015 From: raguay at customct.com (Richard Guay) Date: Wed, 04 Mar 2015 22:36:01 +0700 Subject: [Haskell-beginners] Alfred Programs in Haskell In-Reply-To: <87sidklt6n.fsf@ilxwinb01.fritz.box> References: <54F69A50.4030308@customct.com> <54F71040.40609@customct.com> <87sidklt6n.fsf@ilxwinb01.fritz.box> Message-ID: <54F72661.1030409@customct.com> Hi, Sorry. I found my mistake. I figured my newness in the language was showing, so I asked for help. But, to my surprise, I have been modifying the function for the cache file and testing the data file. :Palm Plant:. Sorry for wasting your time. It is working. Richard Thomas Bach wrote: > > Richard Guay writes: > >> >> It's not a file permission problem because it works great when the >> file exists. But, when the file doesn't exist, it still tries to read >> the file. > > > Is this also the case with the version provided by Kim-Ee Yeoh? > >> >> It acts like the file is there when it isn't. In ghci, it returns the >> true boolean when the file is there and a false when it isn't. But, in >> the program, it is always executing the readFile. > > > This is most unlikely a problem of ghc, i.e. I think there is some > problem in your programs logic. Can you provide further code possibly > restricting it to a minimal breaking example? > > Also: have you tried running the function in question in ghci? > > Regards > > Thomas. > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: From sean at objitsu.com Wed Mar 4 16:09:59 2015 From: sean at objitsu.com (emacstheviking) Date: Wed, 4 Mar 2015 16:09:59 +0000 Subject: [Haskell-beginners] LTS is good but... In-Reply-To: References: Message-ID: OK, having installed it, am I now at liberty to use the LTS instructions to once again attempt to start an OpenGL project? On 4 March 2015 at 15:31, Michael Snoyman wrote: > > > On Wed, Mar 4, 2015 at 4:32 PM Brandon Allbery > wrote: > >> On Wed, Mar 4, 2015 at 4:25 AM, emacstheviking wrote: >> >>> What is the *preferred* way to get the lastest for OSX: Using homebrew, >>> macports or the Haskell Platform. I *used* to use the platform installer >>> but for some reason (cabal I expect!) I started trying out other ways... >> >> >> Depends on who you ask. I use MacPorts and keep it updated, but >> please-root-me (aka Homebrew) is preferred by most people these days. You >> will find people arguing that you should use the Platform and people who >> insist you should always install just ghc and cabal, or people who insist >> you shouldn't ever look beyond Stackage (great if Stackage bothers to >> acknowledge that the library you need exists). >> >> >> > Just to clarify, because there seems to be some confusion in your comments > on Stackage. When someone sets up a project to use Stackage[1], you still > have full access to all packages on Hackage, there just isn't any way to be > certain the packages will compile reliably (which is the case with > installing from Hackage as well). And getting a package into Stackage is a > simple, open procedure[2] which anyone is allowed to participate in. > > In other words: Stackage acknowledges the existence of every package on > Hackage, and can provide build guarantees for any package that is added to > its build-constraints file. > > [1] Minimal procedure: run `wget http://www.stackage.org/lts/cabal.config` > > [2] https://github.com/fpco/stackage#get-your-package-included > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From michael at snoyman.com Wed Mar 4 16:16:29 2015 From: michael at snoyman.com (Michael Snoyman) Date: Wed, 04 Mar 2015 16:16:29 +0000 Subject: [Haskell-beginners] LTS is good but... References: Message-ID: Yes. On Wed, Mar 4, 2015, 6:10 PM emacstheviking wrote: > OK, having installed it, am I now at liberty to use the LTS instructions > to once again attempt to start an OpenGL project? > > > > On 4 March 2015 at 15:31, Michael Snoyman wrote: > >> >> >> On Wed, Mar 4, 2015 at 4:32 PM Brandon Allbery >> wrote: >> >>> On Wed, Mar 4, 2015 at 4:25 AM, emacstheviking >>> wrote: >>> >>>> What is the *preferred* way to get the lastest for OSX: Using homebrew, >>>> macports or the Haskell Platform. I *used* to use the platform installer >>>> but for some reason (cabal I expect!) I started trying out other ways... >>> >>> >>> Depends on who you ask. I use MacPorts and keep it updated, but >>> please-root-me (aka Homebrew) is preferred by most people these days. You >>> will find people arguing that you should use the Platform and people who >>> insist you should always install just ghc and cabal, or people who insist >>> you shouldn't ever look beyond Stackage (great if Stackage bothers to >>> acknowledge that the library you need exists). >>> >>> >>> >> Just to clarify, because there seems to be some confusion in your >> comments on Stackage. When someone sets up a project to use Stackage[1], >> you still have full access to all packages on Hackage, there just isn't any >> way to be certain the packages will compile reliably (which is the case >> with installing from Hackage as well). And getting a package into Stackage >> is a simple, open procedure[2] which anyone is allowed to participate in. >> >> In other words: Stackage acknowledges the existence of every package on >> Hackage, and can provide build guarantees for any package that is added to >> its build-constraints file. >> >> [1] Minimal procedure: run `wget >> http://www.stackage.org/lts/cabal.config` >> >> [2] https://github.com/fpco/stackage#get-your-package-included >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From konstantin.saveljev at gmail.com Thu Mar 5 13:43:30 2015 From: konstantin.saveljev at gmail.com (Konstantin Saveljev) Date: Thu, 5 Mar 2015 15:43:30 +0200 Subject: [Haskell-beginners] cyclic dependency problem Message-ID: Hello, I'm having some trouble with cyclic dependency. My simplified version of hierarchy: module A where import MyState data A a = A (StateT MyState IO a) deriving (...) Now there is a module MyState: module MyState where import SomeType data MyState = MyState { st :: SomeType, ... } Finally the module that introduces cyclic dependency: module SomeType where import A data SomeType = SomeType { f :: A (), ... } I have been suggested to move the types into one module and then import it wherever needed. But the problem is that even if I put them into one file those three data types still form a cyclic dependency and compiler throws errors saying "i don't know about this" So if I have a single module: data A a = A (StateT MyState IO a) deriving (...) data MyState = MyState { st :: SomeType, ... } data SomeType = SomeType { f :: A (), ... } With this setup the compiler is gonna tell us it doesn't know about MyState. And no matter how we shuffle these types within a file we are still getting some "unknowns" How would one approach such a problem? Best regards, Konstantin -------------- next part -------------- An HTML attachment was scrubbed... URL: From fa-ml at ariis.it Thu Mar 5 13:54:13 2015 From: fa-ml at ariis.it (Francesco Ariis) Date: Thu, 5 Mar 2015 14:54:13 +0100 Subject: [Haskell-beginners] cyclic dependency problem In-Reply-To: References: Message-ID: <20150305135413.GA11695@x60s.casa> On Thu, Mar 05, 2015 at 03:43:30PM +0200, Konstantin Saveljev wrote: > I'm having some trouble with cyclic dependency. > > [..] > > So if I have a single module: > > data A a = A (StateT MyState IO a) deriving (...) > data MyState = MyState { st :: SomeType, ... } > data SomeType = SomeType { f :: A (), ... } > > With this setup the compiler is gonna tell us it doesn't know about > MyState. And no matter how we shuffle these types within a file we are > still getting some "unknowns" Hello Konstantin. I just tried to feed this to ghci: data StateT a b = StateT a b data A a = A (StateT MyState (IO a)) data MyState = MyState { st :: SomeType } data SomeType = SomeType { f :: A () } and it works. I think the deriving clause is causing problems (not surprisingly); writing the instance out yourself should solve it. From amindfv at gmail.com Thu Mar 5 14:25:03 2015 From: amindfv at gmail.com (amindfv at gmail.com) Date: Thu, 5 Mar 2015 09:25:03 -0500 Subject: [Haskell-beginners] cyclic dependency problem In-Reply-To: References: Message-ID: El Mar 5, 2015, a las 8:43, Konstantin Saveljev escribi?: > Hello, > > I'm having some trouble with cyclic dependency. > > My simplified version of hierarchy: > > module A where > > import MyState > > data A a = A (StateT MyState IO a) deriving (...) > > Now there is a module MyState: > > module MyState where > > import SomeType > > data MyState = MyState { st :: SomeType, ... } > > Finally the module that introduces cyclic dependency: > > module SomeType where > > import A > > data SomeType = SomeType { f :: A (), ... } > > I have been suggested to move the types into one module and then import it wherever needed. But the problem is that even if I put them into one file those three data types still form a cyclic dependency and compiler throws errors saying "i don't know about this" > > So if I have a single module: > > data A a = A (StateT MyState IO a) deriving (...) > data MyState = MyState { st :: SomeType, ... } > data SomeType = SomeType { f :: A (), ... } > > With this setup the compiler is gonna tell us it doesn't know about MyState. And no matter how we shuffle these types within a file we are still getting some "unknowns" > Did you try it? It should work fine -- haskell doesn't care about the order of data declarations within a file. Tom > How would one approach such a problem? > > Best regards, > Konstantin > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From konstantin.saveljev at gmail.com Thu Mar 5 14:37:02 2015 From: konstantin.saveljev at gmail.com (Konstantin Saveljev) Date: Thu, 5 Mar 2015 16:37:02 +0200 Subject: [Haskell-beginners] cyclic dependency problem In-Reply-To: References: Message-ID: I believe Francesco has a point here. I do have "deriving (MonadState MyState)" which is probably causing the problem. Unfortunately I'm not capable of writing the instance myself. Maybe someone could help me? My full declaration looks something like this: newtype X a = X (StateT MyState (ExceptT String IO) a) deriving (Functor, Applicative, Monad, MonadIO, MonadError String, MonadState MyState) If I was to remove "MonadState MyState" from the "deriving" section, how would one implement it? Konstantin On Thu, Mar 5, 2015 at 4:25 PM, wrote: > > > El Mar 5, 2015, a las 8:43, Konstantin Saveljev < > konstantin.saveljev at gmail.com> escribi?: > > > Hello, > > > > I'm having some trouble with cyclic dependency. > > > > My simplified version of hierarchy: > > > > module A where > > > > import MyState > > > > data A a = A (StateT MyState IO a) deriving (...) > > > > Now there is a module MyState: > > > > module MyState where > > > > import SomeType > > > > data MyState = MyState { st :: SomeType, ... } > > > > Finally the module that introduces cyclic dependency: > > > > module SomeType where > > > > import A > > > > data SomeType = SomeType { f :: A (), ... } > > > > I have been suggested to move the types into one module and then import > it wherever needed. But the problem is that even if I put them into one > file those three data types still form a cyclic dependency and compiler > throws errors saying "i don't know about this" > > > > So if I have a single module: > > > > data A a = A (StateT MyState IO a) deriving (...) > > data MyState = MyState { st :: SomeType, ... } > > data SomeType = SomeType { f :: A (), ... } > > > > With this setup the compiler is gonna tell us it doesn't know about > MyState. And no matter how we shuffle these types within a file we are > still getting some "unknowns" > > > > Did you try it? It should work fine -- haskell doesn't care about the > order of data declarations within a file. > > Tom > > > > How would one approach such a problem? > > > > Best regards, > > Konstantin > > _______________________________________________ > > Beginners mailing list > > Beginners at haskell.org > > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From konstantin.saveljev at gmail.com Thu Mar 5 14:50:43 2015 From: konstantin.saveljev at gmail.com (Konstantin Saveljev) Date: Thu, 5 Mar 2015 16:50:43 +0200 Subject: [Haskell-beginners] cyclic dependency problem In-Reply-To: References: Message-ID: Would this be a correct implementation?: {-# LANGUAGE MultiParamTypeClasses #-} -- for some reason compiler says to use it ? import qualified Control.Monad.State.Lazy as Lazy instance MonadState MyState X where get = X Lazy.get put s = X $ Lazy.put s Konstantin On Thu, Mar 5, 2015 at 4:37 PM, Konstantin Saveljev < konstantin.saveljev at gmail.com> wrote: > I believe Francesco has a point here. I do have "deriving (MonadState > MyState)" which is probably causing the problem. > > Unfortunately I'm not capable of writing the instance myself. Maybe > someone could help me? > > My full declaration looks something like this: > > newtype X a = X (StateT MyState (ExceptT String IO) a) > deriving (Functor, Applicative, Monad, MonadIO, > MonadError String, MonadState MyState) > > If I was to remove "MonadState MyState" from the "deriving" section, how > would one implement it? > > > Konstantin > > On Thu, Mar 5, 2015 at 4:25 PM, wrote: > >> >> >> El Mar 5, 2015, a las 8:43, Konstantin Saveljev < >> konstantin.saveljev at gmail.com> escribi?: >> >> > Hello, >> > >> > I'm having some trouble with cyclic dependency. >> > >> > My simplified version of hierarchy: >> > >> > module A where >> > >> > import MyState >> > >> > data A a = A (StateT MyState IO a) deriving (...) >> > >> > Now there is a module MyState: >> > >> > module MyState where >> > >> > import SomeType >> > >> > data MyState = MyState { st :: SomeType, ... } >> > >> > Finally the module that introduces cyclic dependency: >> > >> > module SomeType where >> > >> > import A >> > >> > data SomeType = SomeType { f :: A (), ... } >> > >> > I have been suggested to move the types into one module and then import >> it wherever needed. But the problem is that even if I put them into one >> file those three data types still form a cyclic dependency and compiler >> throws errors saying "i don't know about this" >> > >> > So if I have a single module: >> > >> > data A a = A (StateT MyState IO a) deriving (...) >> > data MyState = MyState { st :: SomeType, ... } >> > data SomeType = SomeType { f :: A (), ... } >> > >> > With this setup the compiler is gonna tell us it doesn't know about >> MyState. And no matter how we shuffle these types within a file we are >> still getting some "unknowns" >> > >> >> Did you try it? It should work fine -- haskell doesn't care about the >> order of data declarations within a file. >> >> Tom >> >> >> > How would one approach such a problem? >> > >> > Best regards, >> > Konstantin >> > _______________________________________________ >> > Beginners mailing list >> > Beginners at haskell.org >> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From konstantin.saveljev at gmail.com Thu Mar 5 15:07:13 2015 From: konstantin.saveljev at gmail.com (Konstantin Saveljev) Date: Thu, 5 Mar 2015 17:07:13 +0200 Subject: [Haskell-beginners] cyclic dependency problem In-Reply-To: References: Message-ID: Guys, I'm so sorry. It actually turned out to be the problem with makeLenses (from Control.Lens) which I also put into the same module. Now that this stuff is in separate modules everything works and deriving is not a problem. I'm so sorry for wasting you time and thank you very much for your help. Konstantin On Thu, Mar 5, 2015 at 4:50 PM, Konstantin Saveljev < konstantin.saveljev at gmail.com> wrote: > Would this be a correct implementation?: > > {-# LANGUAGE MultiParamTypeClasses #-} -- for some reason compiler > says to use it ? > > import qualified Control.Monad.State.Lazy as Lazy > > instance MonadState MyState X where > get = X Lazy.get > put s = X $ Lazy.put s > > > Konstantin > > On Thu, Mar 5, 2015 at 4:37 PM, Konstantin Saveljev < > konstantin.saveljev at gmail.com> wrote: > >> I believe Francesco has a point here. I do have "deriving (MonadState >> MyState)" which is probably causing the problem. >> >> Unfortunately I'm not capable of writing the instance myself. Maybe >> someone could help me? >> >> My full declaration looks something like this: >> >> newtype X a = X (StateT MyState (ExceptT String IO) a) >> deriving (Functor, Applicative, Monad, MonadIO, >> MonadError String, MonadState MyState) >> >> If I was to remove "MonadState MyState" from the "deriving" section, how >> would one implement it? >> >> >> Konstantin >> >> On Thu, Mar 5, 2015 at 4:25 PM, wrote: >> >>> >>> >>> El Mar 5, 2015, a las 8:43, Konstantin Saveljev < >>> konstantin.saveljev at gmail.com> escribi?: >>> >>> > Hello, >>> > >>> > I'm having some trouble with cyclic dependency. >>> > >>> > My simplified version of hierarchy: >>> > >>> > module A where >>> > >>> > import MyState >>> > >>> > data A a = A (StateT MyState IO a) deriving (...) >>> > >>> > Now there is a module MyState: >>> > >>> > module MyState where >>> > >>> > import SomeType >>> > >>> > data MyState = MyState { st :: SomeType, ... } >>> > >>> > Finally the module that introduces cyclic dependency: >>> > >>> > module SomeType where >>> > >>> > import A >>> > >>> > data SomeType = SomeType { f :: A (), ... } >>> > >>> > I have been suggested to move the types into one module and then >>> import it wherever needed. But the problem is that even if I put them into >>> one file those three data types still form a cyclic dependency and compiler >>> throws errors saying "i don't know about this" >>> > >>> > So if I have a single module: >>> > >>> > data A a = A (StateT MyState IO a) deriving (...) >>> > data MyState = MyState { st :: SomeType, ... } >>> > data SomeType = SomeType { f :: A (), ... } >>> > >>> > With this setup the compiler is gonna tell us it doesn't know about >>> MyState. And no matter how we shuffle these types within a file we are >>> still getting some "unknowns" >>> > >>> >>> Did you try it? It should work fine -- haskell doesn't care about the >>> order of data declarations within a file. >>> >>> Tom >>> >>> >>> > How would one approach such a problem? >>> > >>> > Best regards, >>> > Konstantin >>> > _______________________________________________ >>> > Beginners mailing list >>> > Beginners at haskell.org >>> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From objitsu at gmail.com Thu Mar 5 15:22:27 2015 From: objitsu at gmail.com (emacstheviking) Date: Thu, 5 Mar 2015 15:22:27 +0000 Subject: [Haskell-beginners] Using LTS et. al, a small thank you. Message-ID: First, find yourself a Pharrel Williams youtube video of Happy! ;) It might seem crazy what I'm about to say Functional is here, you can take a break No more OO confusion that takes up too much space Punch the air like you don't care it's cool as I say... Because I code Haskell Code along if you feel like a project without a boss Because I code Haskell Code along if you know that OO is just a bunch of dross Because I code Haskell Code along if you know what productivity is to you Because I code Haskell Clap along if you that's what you wanna do I am sure I could write more but that floated in out of nowhere and stuck as the song came on the radio!! LMAO In all honesty, I have now got OpenGL, http-client and a bunch of stuff all playing nicely. Thanks very much everybody for your help yesterday, it's noce to be hacking Haskell once more. I'm happy.......... -------------- next part -------------- An HTML attachment was scrubbed... URL: From defigueiredo at ucdavis.edu Thu Mar 5 18:30:09 2015 From: defigueiredo at ucdavis.edu (Dimitri DeFigueiredo) Date: Thu, 05 Mar 2015 15:30:09 -0300 Subject: [Haskell-beginners] Using LTS et. al, a small thank you. In-Reply-To: References: Message-ID: <54F8A0B1.3000703@ucdavis.edu> This is the friendliest mailing list I have ever subscribed to. The people in this list are so nice that even if Haskell were not so wonderfully elegant, I would like to learn it just to be able to chat and work with them. :-) Dimitri On 05/03/15 12:22, emacstheviking wrote: > First, find yourself a Pharrel Williams youtube video of Happy! > > ;) > > It might seem crazy what I'm about to say > Functional is here, you can take a break > No more OO confusion that takes up too much space > Punch the air like you don't care it's cool as I say... > > Because I code Haskell > Code along if you feel like a project without a boss > Because I code Haskell > Code along if you know that OO is just a bunch of dross > Because I code Haskell > Code along if you know what productivity is to you > Because I code Haskell > Clap along if you that's what you wanna do > > I am sure I could write more but that floated in out of nowhere and > stuck as the song came on the radio!! LMAO > > > In all honesty, I have now got OpenGL, http-client and a bunch of > stuff all playing nicely. Thanks very much everybody for your help > yesterday, it's noce to be hacking Haskell once more. > > I'm happy.......... > > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: From maxwell.j.schneider at gmail.com Fri Mar 6 01:39:13 2015 From: maxwell.j.schneider at gmail.com (Max Schneider) Date: Thu, 5 Mar 2015 20:39:13 -0500 Subject: [Haskell-beginners] <$> and <*> pronunciation Message-ID: (I really hope 'no stupid questions' holds here) I'm not even going to try framing this into a weighty or practical question; how do you pronounce the <$> and <*> Applicative functions? -------------- next part -------------- An HTML attachment was scrubbed... URL: From fa-ml at ariis.it Fri Mar 6 01:44:44 2015 From: fa-ml at ariis.it (Francesco Ariis) Date: Fri, 6 Mar 2015 02:44:44 +0100 Subject: [Haskell-beginners] <$> and <*> pronunciation In-Reply-To: References: Message-ID: <20150306014444.GA366@x60s.casa> On Thu, Mar 05, 2015 at 08:39:13PM -0500, Max Schneider wrote: > [H]ow do you pronounce the <$> and <*> Applicative functions? Hey Max, <$> is 'mapped to', <*> is 'applied' or 'applied over', f <$> a <*> b -- reads "f mapped to a applied over b", -- but I guess it's more idiomatic and -- clear to say you are 'lifting' -- function f From bob at redivi.com Fri Mar 6 02:32:00 2015 From: bob at redivi.com (Bob Ippolito) Date: Thu, 5 Mar 2015 18:32:00 -0800 Subject: [Haskell-beginners] <$> and <*> pronunciation In-Reply-To: References: Message-ID: Not a stupid question at all! <$> is fmap (literally it is just an operator version of Functor's fmap) <*> is ap (although ap may still be specialized to Monad rather than Applicative, it is the same operation) On Thu, Mar 5, 2015 at 5:39 PM, Max Schneider > wrote: > (I really hope 'no stupid questions' holds here) > I'm not even going to try framing this into a weighty or practical > question; how do you pronounce the <$> and <*> Applicative functions? > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From animeshsaxena at icloud.com Fri Mar 6 05:59:27 2015 From: animeshsaxena at icloud.com (Animesh Saxena) Date: Fri, 06 Mar 2015 05:59:27 +0000 (GMT) Subject: [Haskell-beginners] Function Composition/Map Message-ID: I have a simple function? fmove::Char->(Char,Char)->Char ? ? ?fmove s (x,y) ? ? ?| s == x = y ? ? ?| otherwise = s If I say fmove 'a' ('a','b') it will move to 'b' If I say fmove 'a' ('d','c') it will stay at 'a' Now I am trying to use this for graph, coz one move can result in multiple result nodes. For example in graphs you can have move from a to b and a to c. So I was trying something like this, :t (map fmove s) where s is the set of possible start nodes "abcd" (map fmove s) :: [(Char, Char) -> Char] Now I want to be able to pass the graph to this function and get all possible list of endings. For example my graph can be like?[('a','b'),('b','c'),('c','a'),('c','d'),('e','a')]. You can see that both 'a' and 'd' are possible from node 'c'.? I can see that above type signature is wrong for passing the whole graph coz it accepts?[(Char, Char) -> Char]. I initially started with foldl but problem is recursion on top of foldl. The actual objective of the problem is to figure out if a node is reachable from a start node or not. Hope the problem is clear, can anyone suggest how to convert the map function to accept the graph?? For each of the possible start nodes (accumulating at each step) it should apply it to the same graph.? -Animesh -------------- next part -------------- An HTML attachment was scrubbed... URL: From animeshsaxena at icloud.com Fri Mar 6 06:33:00 2015 From: animeshsaxena at icloud.com (Animesh Saxena) Date: Fri, 06 Mar 2015 06:33:00 +0000 (GMT) Subject: [Haskell-beginners] Function Composition/Map In-Reply-To: Message-ID: <4e94998d-9f46-46e4-9a21-9993a90f08fd@me.com> btw here's my ugly solution type Node = Char type Arc ?= (Node, Node) solve [] arcs = [] solve (x:xs) arcs = (filter (/= ' ') $ map (fmove x) arcs) ++ (solve (filter (/= ' ') $ map (fmove x) arcs) arcs) fmove::Char->(Char,Char)->Char fmove s (x,y) ? ? | s == x = y ? ? | otherwise = ' ' isGraph s e arcs = (length $ filter (==e) (take 20 ?$ solve [s] arcs)) > 0 This last check for isGraph should not use this evil number....."20"...coz of infinite list...Hopefully should be able to figure it out.. -Animesh On Mar 05, 2015, at 09:59 PM, Animesh Saxena wrote: I have a simple function? fmove::Char->(Char,Char)->Char ? ? ?fmove s (x,y) ? ? ?| s == x = y ? ? ?| otherwise = s If I say fmove 'a' ('a','b') it will move to 'b' If I say fmove 'a' ('d','c') it will stay at 'a' Now I am trying to use this for graph, coz one move can result in multiple result nodes. For example in graphs you can have move from a to b and a to c. So I was trying something like this, :t (map fmove s) where s is the set of possible start nodes "abcd" (map fmove s) :: [(Char, Char) -> Char] Now I want to be able to pass the graph to this function and get all possible list of endings. For example my graph can be like?[('a','b'),('b','c'),('c','a'),('c','d'),('e','a')]. You can see that both 'a' and 'd' are possible from node 'c'.? I can see that above type signature is wrong for passing the whole graph coz it accepts?[(Char, Char) -> Char]. I initially started with foldl but problem is recursion on top of foldl. The actual objective of the problem is to figure out if a node is reachable from a start node or not. Hope the problem is clear, can anyone suggest how to convert the map function to accept the graph?? For each of the possible start nodes (accumulating at each step) it should apply it to the same graph.? -Animesh _______________________________________________ Beginners mailing list Beginners at haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: From thbach at students.uni-mainz.de Fri Mar 6 09:59:35 2015 From: thbach at students.uni-mainz.de (Thomas Bach) Date: Fri, 6 Mar 2015 10:59:35 +0100 Subject: [Haskell-beginners] Function Composition/Map In-Reply-To: (Animesh Saxena's message of "Fri, 6 Mar 2015 05:59:27 +0000") References: Message-ID: <87mw3qjvjs.fsf@ilxwinb01.fritz.box> Animesh Saxena writes: > I have a simple function > > fmove::Char->(Char,Char)->Char > fmove s (x,y) > | s == x = y > | otherwise = s > > If I say fmove 'a' ('a','b') it will move to 'b' > If I say fmove 'a' ('d','c') it will stay at 'a' Note that `fmove 'a' ('c','a')` won't move you to 'c' and in general `fmove x (y,z)` will move you to the node ' ' if x /= y. As for the latter I'd suggest to use Maybe to have the possibility of a miss encoded at type level: import Data.Maybe type Node = Char type Edge = (Char,Char) type Graph = [Edge] fmove:: Node -> Edge -> Maybe Node fmove s (x,y) | s == x = Just y | otherwise = Nothing > > Now I am trying to use this for graph, coz one move can result in > multiple result nodes. Using mapMaybe from Data.Maybe: oneHopInGraph :: Graph -> Node -> [Node] oneHopInGraph g n = mapMaybe (fmove n) g > For example in graphs you can have move from a to b and a to c. So I > was trying something like this, > > :t (map fmove s) where s is the set of possible start nodes "abcd" > > (map fmove s) :: [(Char, Char) -> Char] Note that this is equivalent to `((map fmove) s)` ? function application binds most in Haskell. So if you want to map from several start nodes this would be oneHopFromSeveral :: [Node] -> [Edge] -> [[Node]] oneHopFromSeveral ns g = map (oneHopInGraph g) ns > I can see that above type signature is wrong for passing the whole > graph coz it accepts [(Char, Char) -> Char]. I initially started with > foldl but problem is recursion on top of foldl. My suggestion would be to take it easy in the beginning (I take it that you are a beginner): try to write the recursions yourself and really try to wrap your head around types. After writing the recursion by hand start thinking about your code and its types really hard. From time to time folds and maps will jump on you. And these Heureka moments will happen more and more frequently. > The actual objective of the problem is to figure out if a node is > reachable from a start node or not. Hope the problem is clear, can > anyone suggest how to convert the map function to accept the graph? So lets see what we have here the type of the resulting function should be allPossibleHops :: Node -> Graph -> [Node] right? So what is the condition when we can stop? When there aren't any possible hops: allPossibleHops n g | oneHopInGraph g n == [] = [] in the other case the result are the next possible hops plus the result of all possible hops of these hops: | otherwise = nextHops ++ concatMap (flip allPossibleHops g) nextHops where nextHops = oneHopInGraph g n Testing: ?> allPossibleHops 'a' [('a','b'),('b','c'),('c','d'),('e','a')] "bcd" You have to make sure that there aren't any cycles for this solution to work! I hope this helps. Regards Thomas. From objitsu at gmail.com Fri Mar 6 11:16:39 2015 From: objitsu at gmail.com (emacstheviking) Date: Fri, 6 Mar 2015 11:16:39 +0000 Subject: [Haskell-beginners] Using LTS et. al, a small thank you. In-Reply-To: <54F8A0B1.3000703@ucdavis.edu> References: <54F8A0B1.3000703@ucdavis.edu> Message-ID: :) You have a point. I have been on some really uncomfortable lists over the years!! I like the precision of the answers. Haskell hurts your head. (But in a good way). That's a T-shirt slogan right there! Sean. On 5 March 2015 at 18:30, Dimitri DeFigueiredo wrote: > This is the friendliest mailing list I have ever subscribed to. > > The people in this list are so nice that even if Haskell were not so > wonderfully elegant, I would like to learn it just to be able to chat and > work with them. > > :-) > > Dimitri > > > > On 05/03/15 12:22, emacstheviking wrote: > > First, find yourself a Pharrel Williams youtube video of Happy! > > ;) > > It might seem crazy what I'm about to say > Functional is here, you can take a break > No more OO confusion that takes up too much space > Punch the air like you don't care it's cool as I say... > > Because I code Haskell > Code along if you feel like a project without a boss > Because I code Haskell > Code along if you know that OO is just a bunch of dross > Because I code Haskell > Code along if you know what productivity is to you > Because I code Haskell > Clap along if you that's what you wanna do > > I am sure I could write more but that floated in out of nowhere and > stuck as the song came on the radio!! LMAO > > > In all honesty, I have now got OpenGL, http-client and a bunch of stuff > all playing nicely. Thanks very much everybody for your help yesterday, > it's noce to be hacking Haskell once more. > > I'm happy.......... > > > > > _______________________________________________ > Beginners mailing listBeginners at haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From animeshsaxena at icloud.com Sat Mar 7 04:42:21 2015 From: animeshsaxena at icloud.com (Animesh Saxena) Date: Sat, 07 Mar 2015 04:42:21 +0000 (GMT) Subject: [Haskell-beginners] State Monad stack example Message-ID: I am trying to relate the state monad to a stack example and somehow found it easy to get recursively confused! instance Monad (State s) where ? ? return x = State $ \s -> (x,s) ? ? (State h) >>= f = State $ \s -> let (a, newState) = h s ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? (State g) = f a ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?in g newState Considering the stack computation stackManip stack = let? ? ? ? ? ? ? ? ((), newStack1) = push 3 stack ? ? ? ? ? ? ? (a, newStack2) = pop newStack1 ? ? ? ? ? ? ? ?in pop newStack2 in do notation this would become? do ? ? ?push 3 ? ? ?a <- pop ? ? ?pop If I consider the first computation push 3 >>= pop and try to translate it to the definition there are problems.... Copy paste again, I have? ? ? (State h) >>= f = State $ \s -> let (a, newState) = h s ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? (State g) = f a ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?in g newState f is the push function to which we are shoving the old state. I can't exactly get around to what exactly is the state computation h? Ok assuming it's something which gives me a new state, but then thats push which is function f.? Then push is applied to a which is assuming 3 in this case. This gives me a new state, which I would say newStack1 from the stockManip above. Then somehow I apply g to newState?? All the more confusion. Back to the question what exactly is state computation and how is it different from f? It seems to be the same function? -Animesh ? ? ? ? ? ? ? ? ? ? ? ? ? ? -------------- next part -------------- An HTML attachment was scrubbed... URL: From sumit.sahrawat.apm13 at iitbhu.ac.in Sat Mar 7 05:09:00 2015 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Sat, 7 Mar 2015 10:39:00 +0530 Subject: [Haskell-beginners] State Monad stack example In-Reply-To: References: Message-ID: I won't comment on what state exactly is, but you can read up on that and gain some intuition here: https://en.wikibooks.org/wiki/Haskell/Understanding_monads/State It's helpful to implement it using a pen and paper, and consider how the state flows and gets transformed. According to the below example, stackManip stack = let ((), newStack1) = push 3 stack (a, newStack2) = pop newStack1 in pop newStack2 We get, push :: a -> Stack a -> ((), Stack a) -- Assuming 'Stack a' is a defined datatype pop :: Stack a -> (a, Stack a) -- Representing a stack with elements of type 'a' Thus, push 3 >>= pop ~~ (Stack a -> ((), Stack a)) >>= (Stack a -> (a, Stack a)) { Replacing by types } Bind (>>=) has the type, (for "State s") (>>=) :: State s a -> (a -> State s b) -> State s b This is a type mismatch. The conversion to do syntax is at fault here. First, you must write the computation using bind (>>=), and then convert to do-notation. On 7 March 2015 at 10:12, Animesh Saxena wrote: > I am trying to relate the state monad to a stack example and somehow found > it easy to get recursively confused! > > instance Monad (State s) where > return x = State $ \s -> (x,s) > (State h) >>= f = State $ \s -> let (a, newState) = h s > (State g) = f a > in g newState > > Considering the stack computation > > stackManip stack = let > ((), newStack1) = push 3 stack > (a, newStack2) = pop newStack1 > in pop newStack2 > > in do notation this would become > do > push 3 > a <- pop > pop > > If I consider the first computation push 3 >>= pop and try to translate it > to the definition there are problems.... > Copy paste again, I have > (State h) >>= f = State $ \s -> let (a, newState) = h s > (State g) = f a > in g newState > > f is the push function to which we are shoving the old state. I can't > exactly get around to what exactly is the state computation h? Ok assuming > it's something which gives me a new state, but then thats push which is > function f. > Then push is applied to a which is assuming 3 in this case. This gives me > a new state, which I would say newStack1 from the stockManip above. > > Then somehow I apply g to newState?? All the more confusion. Back to the > question what exactly is state computation and how is it different from f? > It seems to be the same function? > > > -Animesh > > > > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -- Regards Sumit Sahrawat -------------- next part -------------- An HTML attachment was scrubbed... URL: From edwards.benj at gmail.com Sat Mar 7 09:45:00 2015 From: edwards.benj at gmail.com (Benjamin Edwards) Date: Sat, 07 Mar 2015 09:45:00 +0000 Subject: [Haskell-beginners] State Monad stack example References: Message-ID: I gave an expansion of the state monad for a different computation on Reddit some time ago. Perhaps it will be useful to you: http://www.reddit.com/r/haskell/comments/25fnrj/nicta_course_help_with_state_exercise/ Best, Ben On Sat, 7 Mar 2015 5:09 am Sumit Sahrawat, Maths & Computing, IIT (BHU) < sumit.sahrawat.apm13 at iitbhu.ac.in> wrote: > I won't comment on what state exactly is, but you can read up on that and > gain some intuition here: > https://en.wikibooks.org/wiki/Haskell/Understanding_monads/State > It's helpful to implement it using a pen and paper, and consider how the > state flows and gets transformed. > > According to the below example, > > stackManip stack = > let ((), newStack1) = push 3 stack > (a, newStack2) = pop newStack1 > in pop newStack2 > > We get, > > push :: a -> Stack a -> ((), Stack a) -- Assuming 'Stack a' is a > defined datatype > pop :: Stack a -> (a, Stack a) -- Representing a stack with > elements of type 'a' > > Thus, > > push 3 >>= pop > ~~ (Stack a -> ((), Stack a)) >>= (Stack a -> (a, Stack a)) > { Replacing by types } > > Bind (>>=) has the type, (for "State s") > > (>>=) :: State s a -> (a -> State s b) -> State s b > > This is a type mismatch. The conversion to do syntax is at fault here. > First, you must write the computation using bind (>>=), and then convert > to do-notation. > > On 7 March 2015 at 10:12, Animesh Saxena wrote: > >> I am trying to relate the state monad to a stack example and somehow >> found it easy to get recursively confused! >> >> instance Monad (State s) where >> return x = State $ \s -> (x,s) >> (State h) >>= f = State $ \s -> let (a, newState) = h s >> (State g) = f a >> in g newState >> >> Considering the stack computation >> >> stackManip stack = let >> ((), newStack1) = push 3 stack >> (a, newStack2) = pop newStack1 >> in pop newStack2 >> >> in do notation this would become >> do >> push 3 >> a <- pop >> pop >> >> If I consider the first computation push 3 >>= pop and try to translate >> it to the definition there are problems.... >> Copy paste again, I have >> (State h) >>= f = State $ \s -> let (a, newState) = h s >> (State g) = f a >> in g newState >> >> f is the push function to which we are shoving the old state. I can't >> exactly get around to what exactly is the state computation h? Ok assuming >> it's something which gives me a new state, but then thats push which is >> function f. >> Then push is applied to a which is assuming 3 in this case. This gives me >> a new state, which I would say newStack1 from the stockManip above. >> >> Then somehow I apply g to newState?? All the more confusion. Back to the >> question what exactly is state computation and how is it different from f? >> It seems to be the same function? >> >> >> -Animesh >> >> >> >> >> >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> > > > -- > Regards > > Sumit Sahrawat > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From animeshsaxena at icloud.com Sat Mar 7 17:34:23 2015 From: animeshsaxena at icloud.com (Animesh Saxena) Date: Sat, 07 Mar 2015 17:34:23 +0000 (GMT) Subject: [Haskell-beginners] State Monad stack example Message-ID: Thanks for the links, I am able to get my head around this a bit.? Here's my simple question 1. In the stack example what is the state. As per my understanding the state is the new stack. If above statement is correct than by definition of >>= ? (>>=) :: State s a -> (a -> State s b) -> State s b push 3 stack? This returns ((), newstack1) Now in this case the state or context is newstack1 which has to be passed to the next function if i apply >>=. push 3 stack >>= pop newstack1 This might make sense coz I am shoving (or binding) the state to the pop function. State in this case is the stack which is being passed around or shoved around. Problem is pop doesn't need "a" argument like the definition of (>>=) indicates. It can very well produce a new state or return ?a new state.? So if state = stack then this makes sense to me, where am i wrong...?? push 3 stack >>= pop newstack1 On Mar 06, 2015, at 09:09 PM, "Sumit Sahrawat, Maths & Computing, IIT (BHU)" wrote: I won't comment on what state exactly is, but you can read up on that and gain some intuition here: https://en.wikibooks.org/wiki/Haskell/Understanding_monads/State It's helpful to implement it using a pen and paper, and consider how the state flows and gets transformed. According to the below example, ? stackManip stack = ? ? let?((), newStack1) = push 3 stack ? ? ? ? (a, newStack2) ?= pop newStack1 ? ? in pop newStack2 We get, ? push :: a -> Stack a -> ((), Stack a) ? ?-- Assuming 'Stack a' is a defined datatype ? pop ?:: Stack a -> (a, Stack a) ? ? ? ? ?-- Representing a stack with elements of type 'a' Thus, ? ? push 3 >>= pop ~~ ?(Stack a -> ((), Stack a)) >>= (Stack a -> (a, Stack a)) ? ? ? ? ? ? ? { Replacing by types } Bind (>>=) has the type, (for "State s") ? (>>=) :: State s a -> (a -> State s b) -> State s b This is a type mismatch. The conversion to do syntax is at fault here. First, you must write the computation using bind (>>=), and then convert to do-notation. On 7 March 2015 at 10:12, Animesh Saxena wrote: I am trying to relate the state monad to a stack example and somehow found it easy to get recursively confused! instance Monad (State s) where ? ? return x = State $ \s -> (x,s) ? ? (State h) >>= f = State $ \s -> let (a, newState) = h s ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? (State g) = f a ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?in g newState Considering the stack computation stackManip stack = let? ? ? ? ? ? ? ? ((), newStack1) = push 3 stack ? ? ? ? ? ? ? (a, newStack2) = pop newStack1 ? ? ? ? ? ? ? ?in pop newStack2 in do notation this would become? do ? ? ?push 3 ? ? ?a <- pop ? ? ?pop If I consider the first computation push 3 >>= pop and try to translate it to the definition there are problems.... Copy paste again, I have? ? ? (State h) >>= f = State $ \s -> let (a, newState) = h s ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? (State g) = f a ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?in g newState f is the push function to which we are shoving the old state. I can't exactly get around to what exactly is the state computation h? Ok assuming it's something which gives me a new state, but then thats push which is function f.? Then push is applied to a which is assuming 3 in this case. This gives me a new state, which I would say newStack1 from the stockManip above. Then somehow I apply g to newState?? All the more confusion. Back to the question what exactly is state computation and how is it different from f? It seems to be the same function? -Animesh ? ? ? ? ? ? ? ? ? ? ? ? ? ? _______________________________________________ Beginners mailing list Beginners at haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -- Regards Sumit Sahrawat _______________________________________________ Beginners mailing list Beginners at haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeffbrown.the at gmail.com Sat Mar 7 21:52:08 2015 From: jeffbrown.the at gmail.com (Jeffrey Brown) Date: Sat, 7 Mar 2015 13:52:08 -0800 Subject: [Haskell-beginners] Laziness to efficiently get one element from a set Message-ID: Hi, Suppose S is a big set, and I'd like to access just a single element from it. The only natural way I've come up with to do that is this: head $ Data.Set.toList S. If I do that, am I correct that Haskell will not try to convert all of S to a list; instead it will only convert one element, and then return it, and leave the rest of the list unevaluated? Thanks, Jeff -------------- next part -------------- An HTML attachment was scrubbed... URL: From thbach at students.uni-mainz.de Sat Mar 7 23:49:43 2015 From: thbach at students.uni-mainz.de (Thomas Bach) Date: Sun, 8 Mar 2015 00:49:43 +0100 Subject: [Haskell-beginners] Laziness to efficiently get one element from a set In-Reply-To: (Jeffrey Brown's message of "Sat, 7 Mar 2015 13:52:08 -0800") References: Message-ID: <87385gwep4.fsf@ilxwinb01.fritz.box> Jeffrey Brown writes: > head $ Data.Set.toList S. If I do that, am I correct that Haskell will > not try to convert all of S to a list; instead it will only convert > one element, and then return it, and leave the rest of the list > unevaluated? This is how toList from Data.Set.Base is defined in containers-0.5.0: {-------------------------------------------------------------------- Lists --------------------------------------------------------------------} -- | /O(n)/. Convert the set to a list of elements. Subject to list fusion. toList :: Set a -> [a] toList = toAscList -- | /O(n)/. Convert the set to an ascending list of elements. Subject to list fusion. toAscList :: Set a -> [a] toAscList = foldr (:) [] The buzzword you are looking for is list fusion: http://stackoverflow.com/questions/10945429/haskell-list-fusion-where-is-it-needed Regards Thomas Bach. From jeffbrown.the at gmail.com Sun Mar 8 00:11:29 2015 From: jeffbrown.the at gmail.com (Jeffrey Brown) Date: Sat, 7 Mar 2015 16:11:29 -0800 Subject: [Haskell-beginners] Laziness to efficiently get one element from a set In-Reply-To: <87385gwep4.fsf@ilxwinb01.fritz.box> References: <87385gwep4.fsf@ilxwinb01.fritz.box> Message-ID: Fantastic! Thanks, Thomas! On Sat, Mar 7, 2015 at 3:49 PM, Thomas Bach wrote: > Jeffrey Brown writes: > > > head $ Data.Set.toList S. If I do that, am I correct that Haskell will > > not try to convert all of S to a list; instead it will only convert > > one element, and then return it, and leave the rest of the list > > unevaluated? > > This is how toList from Data.Set.Base is defined in containers-0.5.0: > > {-------------------------------------------------------------------- > Lists > --------------------------------------------------------------------} > -- | /O(n)/. Convert the set to a list of elements. Subject to list fusion. > toList :: Set a -> [a] > toList = toAscList > > -- | /O(n)/. Convert the set to an ascending list of elements. Subject to > list fusion. > toAscList :: Set a -> [a] > toAscList = foldr (:) [] > > The buzzword you are looking for is list fusion: > > > http://stackoverflow.com/questions/10945429/haskell-list-fusion-where-is-it-needed > > Regards > > Thomas Bach. > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From animeshsaxena at icloud.com Sun Mar 8 03:55:09 2015 From: animeshsaxena at icloud.com (Animesh Saxena) Date: Sun, 08 Mar 2015 11:55:09 +0800 Subject: [Haskell-beginners] State Monad stack example In-Reply-To: References: Message-ID: <317E110F-207A-4B0B-9531-A7CCF7BCAC57@icloud.com> Ok I got the confusion clear, I was referring to the wrong definitions of push and pop pop = Stack $ (\x:xs) -> (x,xs) push a = State $ \xs -> ((), xs) Now the do operation makes sense coz now I can relate all this to simple monads?. (>>=) :: Monad m => m a -> (a -> m b) -> m b Where m = state s being shoved around! -Animesh > On Mar 8, 2015, at 1:34 AM, Animesh Saxena wrote: > > Thanks for the links, I am able to get my head around this a bit. > > Here's my simple question > 1. In the stack example what is the state. As per my understanding the state is the new stack. > If above statement is correct than by definition of >>= > >> (>>=) :: State s a -> (a -> State s b) -> State s b > > > push 3 stack > This returns ((), newstack1) > Now in this case the state or context is newstack1 which has to be passed to the next function if i apply >>=. > push 3 stack >>= pop newstack1 > This might make sense coz I am shoving (or binding) the state to the pop function. State in this case is the stack which is being passed around or shoved around. Problem is pop doesn't need "a" argument like the definition of (>>=) indicates. It can very well produce a new state or return a new state. > > So if state = stack then this makes sense to me, where am i wrong...?? > > push 3 stack >>= pop newstack1 > > On Mar 06, 2015, at 09:09 PM, "Sumit Sahrawat, Maths & Computing, IIT (BHU)" wrote: > >> I won't comment on what state exactly is, but you can read up on that and gain some intuition here: https://en.wikibooks.org/wiki/Haskell/Understanding_monads/State >> It's helpful to implement it using a pen and paper, and consider how the state flows and gets transformed. >> >> According to the below example, >> >> stackManip stack = >> let ((), newStack1) = push 3 stack >> (a, newStack2) = pop newStack1 >> in pop newStack2 >> >> We get, >> >> push :: a -> Stack a -> ((), Stack a) -- Assuming 'Stack a' is a defined datatype >> pop :: Stack a -> (a, Stack a) -- Representing a stack with elements of type 'a' >> >> Thus, >> >> push 3 >>= pop >> ~~ (Stack a -> ((), Stack a)) >>= (Stack a -> (a, Stack a)) { Replacing by types } >> >> Bind (>>=) has the type, (for "State s") >> >> (>>=) :: State s a -> (a -> State s b) -> State s b >> >> This is a type mismatch. The conversion to do syntax is at fault here. >> First, you must write the computation using bind (>>=), and then convert to do-notation. >> >> On 7 March 2015 at 10:12, Animesh Saxena > wrote: >> I am trying to relate the state monad to a stack example and somehow found it easy to get recursively confused! >> >> instance Monad (State s) where >> return x = State $ \s -> (x,s) >> (State h) >>= f = State $ \s -> let (a, newState) = h s >> (State g) = f a >> in g newState >> >> Considering the stack computation >> >> stackManip stack = let >> ((), newStack1) = push 3 stack >> (a, newStack2) = pop newStack1 >> in pop newStack2 >> >> in do notation this would become >> do >> push 3 >> a <- pop >> pop >> >> If I consider the first computation push 3 >>= pop and try to translate it to the definition there are problems.... >> Copy paste again, I have >> (State h) >>= f = State $ \s -> let (a, newState) = h s >> (State g) = f a >> in g newState >> >> f is the push function to which we are shoving the old state. I can't exactly get around to what exactly is the state computation h? Ok assuming it's something which gives me a new state, but then thats push which is function f. >> Then push is applied to a which is assuming 3 in this case. This gives me a new state, which I would say newStack1 from the stockManip above. >> >> Then somehow I apply g to newState?? All the more confusion. Back to the question what exactly is state computation and how is it different from f? It seems to be the same function? >> >> >> -Animesh >> >> >> >> >> >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> >> >> >> -- >> Regards >> >> Sumit Sahrawat >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: From apfelmus at quantentunnel.de Sun Mar 8 08:59:47 2015 From: apfelmus at quantentunnel.de (Heinrich Apfelmus) Date: Sun, 08 Mar 2015 09:59:47 +0100 Subject: [Haskell-beginners] Laziness to efficiently get one element from a set In-Reply-To: <87385gwep4.fsf@ilxwinb01.fritz.box> References: <87385gwep4.fsf@ilxwinb01.fritz.box> Message-ID: Thomas Bach wrote: > Jeffrey Brown writes: > >> head $ Data.Set.toList S. If I do that, am I correct that Haskell will >> not try to convert all of S to a list; instead it will only convert >> one element, and then return it, and leave the rest of the list >> unevaluated? > > This is how toList from Data.Set.Base is defined in containers-0.5.0: > > {-------------------------------------------------------------------- > Lists > --------------------------------------------------------------------} > -- | /O(n)/. Convert the set to a list of elements. Subject to list fusion. > toList :: Set a -> [a] > toList = toAscList > > -- | /O(n)/. Convert the set to an ascending list of elements. Subject to list fusion. > toAscList :: Set a -> [a] > toAscList = foldr (:) [] > > The buzzword you are looking for is list fusion: > > http://stackoverflow.com/questions/10945429/haskell-list-fusion-where-is-it-needed Actually, I don't think that list fusion is appropriate here. The `foldr` used in the definition of `toAscList` is from the `Foldable` type class, and implemented specifically for the `Set` data type. It's not the usual fold on lists. Jeffrey, if you want to pick a single element from a `Set`, I would recommend the functions `findMin` or `findMax`. The former satisfies Data.Set.findMin = head . Data.Set.toList so you will get the same element as in your original approach. This time, however, you can be sure that it takes O(log n) time, whereas in the approach using `head`, it depends on the internals of the implementation of `foldr` whether it will take time O(n) or O(log n) or something in between. (In particular, it depends on how lazy the implementation of `foldr` for `Set` is. See [1] for more on lazy evaluation in this / a similar context.) [1]: https://hackhands.com/modular-code-lazy-evaluation-haskell/ Best regards, Heinrich Apfelmus -- http://apfelmus.nfshost.com From dot_wangyushi at yeah.net Sun Mar 8 10:59:57 2015 From: dot_wangyushi at yeah.net (m00nlight) Date: Sun, 8 Mar 2015 18:59:57 +0800 (CST) Subject: [Haskell-beginners] Strange behavior of program Message-ID: <50a09477.2d5.14bf90a9cfb.Coremail.dot_wangyushi@yeah.net> Hi Haskellers, I encounter an strange behavior of haskell program recently. The following is my program ```haskell main = do _ <- getLine arr1 <- getLine _ <- getLine arr2 <- getLine let a = map (read :: String -> Int) (words arr1) b = map (read :: String -> Int) (words arr2) putStrLn $ show $ (foldl (*) 1 a) putStrLn $ show $ a == [1,2,4,8,32,64,128,256,512,1024,2048,4906,8192] putStrLn $ show $ (foldl (*) 1 [1,2,4,8,32,64,128,256,512,1024,2048,4906,8192]) ``` With the input test file as following: ```test.in 13 1 2 4 8 32 64 128 256 512 1024 2048 4906 8192 9 1 3 9 27 81 243 729 2187 6561 ``` The output is as: ```output 0 True 185343439719667835347140608 ``` In fact, from the program, we know that a is equal to list [1,2,4,8,32,64,128,256,512,1024,2048,4906,8192] , but the product of a and the literal list is different. Can anyone tell me why? Thanks --m00nlight -------------- next part -------------- An HTML attachment was scrubbed... URL: From Spam at gettingsharper.de Sun Mar 8 11:22:45 2015 From: Spam at gettingsharper.de (=?windows-1252?Q?Carsten_K=F6nig?=) Date: Sun, 08 Mar 2015 12:22:45 +0100 Subject: [Haskell-beginners] Strange behavior of program In-Reply-To: <50a09477.2d5.14bf90a9cfb.Coremail.dot_wangyushi@yeah.net> References: <50a09477.2d5.14bf90a9cfb.Coremail.dot_wangyushi@yeah.net> Message-ID: <54FC3105.20309@gettingsharper.de> Try > foldl (*) 1 [1,2,4,8,32,64,128,256,512,1024,2048,4906,8192] and then > foldl (*) 1 [1,2,4,8,32,64,128,256,512,1024,2048,4906,8192] :: Int what do you see? You might want to check with > :t foldl (*) 1 [1,2,4,8,32,64,128,256,512,1024,2048,4906,8192] next Am 08.03.2015 um 11:59 schrieb m00nlight: > foldl (*) 1 [1,2,4,8,32,64,128,256,512,1024,2048,4906,8192] From arjanen.loic at gmail.com Sun Mar 8 12:01:44 2015 From: arjanen.loic at gmail.com (arjanen.loic at gmail.com) Date: Sun, 8 Mar 2015 12:01:44 +0000 Subject: [Haskell-beginners] =?utf-8?q?Strange_behavior_of_program?= In-Reply-To: <50a09477.2d5.14bf90a9cfb.Coremail.dot_wangyushi@yeah.net> References: <50a09477.2d5.14bf90a9cfb.Coremail.dot_wangyushi@yeah.net> Message-ID: <54fc3c0b.e22e460a.1f3a.ffff928d@mx.google.com> Hello, Given that you specifically indicated in your code that you wanted Int?s instance of Read and that the result of the product is way over 2 ^ 32 (or 2 ^ 64 for that matter), I?d guess the difference comes from the fact that the product of a is done with type Int (that is, modulo 32 or 64 depending on your computer?s CPU architecture) and the product with the litteral list is done with type Integer because that the type Haskell defaults to in this case. ARJANEN Lo?c Jean David http://blog.luigiscorner.com --- ?Computer science is no more about computers than astronomy is about telescopes, biology is about microscopes, or chemistry is about beakers and test tubes. Science is not about tools. It is about how we use them, and what we find out when we do.? Michael R. Fellows and Ian Parberry De : m00nlight Envoy? : ?dimanche? ?8? ?mars? ?2015 ?21?:?59 ? : The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell Hi Haskellers, I encounter an strange behavior of haskell program recently. The following is my program ```haskell main = do _ <- getLine arr1 <- getLine _ <- getLine arr2 <- getLine let a = map (read :: String -> Int) (words arr1) b = map (read :: String -> Int) (words arr2) putStrLn $ show $ (foldl (*) 1 a) putStrLn $ show $ a == [1,2,4,8,32,64,128,256,512,1024,2048,4906,8192] putStrLn $ show $ (foldl (*) 1 [1,2,4,8,32,64,128,256,512,1024,2048,4906,8192]) ``` With the input test file as following: ```test.in 13 1 2 4 8 32 64 128 256 512 1024 2048 4906 8192 9 1 3 9 27 81 243 729 2187 6561 ``` The output is as: ```output 0 True 185343439719667835347140608 ``` In fact, from the program, we know that a is equal to list [1,2,4,8,32,64,128,256,512,1024,2048,4906,8192] , but the product of a and the literal list is different. Can anyone tell me why? Thanks --m00nlight -------------- next part -------------- An HTML attachment was scrubbed... URL: From dot_wangyushi at yeah.net Sun Mar 8 14:08:39 2015 From: dot_wangyushi at yeah.net (m00nlight) Date: Sun, 8 Mar 2015 22:08:39 +0800 (CST) Subject: [Haskell-beginners] Strange behavior of program In-Reply-To: <54fc3c0b.e22e460a.1f3a.ffff928d@mx.google.com> References: <50a09477.2d5.14bf90a9cfb.Coremail.dot_wangyushi@yeah.net> <54fc3c0b.e22e460a.1f3a.ffff928d@mx.google.com> Message-ID: Carsten and Arjanen, Thanks for your explanation. :) --m00nlight ?2015?03?08 20?01?, "arjanen.loic"??: Hello, Given that you specifically indicated in your code that you wanted Int?s instance of Read and that the result of the product is way over 2 ^ 32 (or 2 ^ 64 for that matter), I?d guess the difference comes from the fact that the product of a is done with type Int (that is, modulo 32 or 64 depending on your computer?s CPU architecture) and the product with the litteral list is done with type Integer because that the type Haskell defaults to in this case. ARJANEN Lo?c Jean David http://blog.luigiscorner.com --- ?Computer science is no more about computers than astronomy is about telescopes, biology is about microscopes, or chemistry is about beakers and test tubes. Science is not about tools. It is about how we use them, and what we find out when we do.? Michael R. Fellows and Ian Parberry De : m00nlight Envoy? : ?dimanche? ?8? ?mars? ?2015 ?21?:?59 ? : The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell Hi Haskellers, I encounter an strange behavior of haskell program recently. The following is my program ```haskell main = do _ <- getLine arr1 <- getLine _ <- getLine arr2 <- getLine let a = map (read :: String -> Int) (words arr1) b = map (read :: String -> Int) (words arr2) putStrLn $ show $ (foldl (*) 1 a) putStrLn $ show $ a == [1,2,4,8,32,64,128,256,512,1024,2048,4906,8192] putStrLn $ show $ (foldl (*) 1 [1,2,4,8,32,64,128,256,512,1024,2048,4906,8192]) ``` With the input test file as following: ```test.in 13 1 2 4 8 32 64 128 256 512 1024 2048 4906 8192 9 1 3 9 27 81 243 729 2187 6561 ``` The output is as: ```output 0 True 185343439719667835347140608 ``` In fact, from the program, we know that a is equal to list [1,2,4,8,32,64,128,256,512,1024,2048,4906,8192] , but the product of a and the literal list is different. Can anyone tell me why? Thanks --m00nlight -------------- next part -------------- An HTML attachment was scrubbed... URL: From Spam at gettingsharper.de Sun Mar 8 14:26:24 2015 From: Spam at gettingsharper.de (=?UTF-8?B?Q2Fyc3RlbiBLw7ZuaWc=?=) Date: Sun, 08 Mar 2015 15:26:24 +0100 Subject: [Haskell-beginners] Strange behavior of program In-Reply-To: References: <50a09477.2d5.14bf90a9cfb.Coremail.dot_wangyushi@yeah.net> <54fc3c0b.e22e460a.1f3a.ffff928d@mx.google.com> Message-ID: <54FC5C10.3080105@gettingsharper.de> No problem - Num can be a bit confusing at first - just make sure to compare the right things ;) Am 08.03.2015 um 15:08 schrieb m00nlight: > Carsten and Arjanen, > > Thanks for your explanation. :) > > > > --m00nlight > > ?2015?03?08 20?01?, "arjanen.loic"??: > > > Hello, > > Given that you specifically indicated in your code that you > wanted Int?s instance of Read and that the result of the product > is way over 2 ^ 32 (or 2 ^ 64 for that matter), I?d guess the > difference comes from the fact that the product of a is done with > type Int (that is, modulo 32 or 64 depending on your computer?s > CPU architecture) and the product with the litteral list is done > with type Integer because that the type Haskell defaults to in > this case. > > ARJANEN Lo?c Jean David > http://blog.luigiscorner.com > --- > ?Computer science is no more about computers than astronomy is > about telescopes, biology is about microscopes, or chemistry is > about beakers and test tubes. Science is not about tools. It is > about how we use them, and what we find out when we do.? > Michael R. Fellows and Ian Parberry > > *De :* m00nlight > *Envoy? :* ?dimanche? ?8? ?mars? ?2015 ?21?:?59 > *? :* The Haskell-Beginners Mailing List - Discussion of primarily > beginner-level topics related to Haskell > > > > Hi Haskellers, > > I encounter an strange behavior of haskell program recently. The > following is my program > > ```haskell > main = do > _ <- getLine > arr1 <- getLine > _ <- getLine > arr2 <- getLine > let a = map (read :: String -> Int) (words arr1) > b = map (read :: String -> Int) (words arr2) > > putStrLn $ show $ (foldl (*) 1 a) > putStrLn $ show $ a == > [1,2,4,8,32,64,128,256,512,1024,2048,4906,8192] > putStrLn $ show $ (foldl (*) 1 > [1,2,4,8,32,64,128,256,512,1024,2048,4906,8192]) > ``` > > With the input test file as following: > > ```test.in > 13 > 1 2 4 8 32 64 128 256 512 1024 2048 4906 8192 > 9 > 1 3 9 27 81 243 729 2187 6561 > ``` > > The output is as: > ```output > 0 > True > 185343439719667835347140608 > ``` > > In fact, from the program, we know that a is equal to list > [1,2,4,8,32,64,128,256,512,1024,2048,4906,8192] , > but the product of a and the literal list is different. > > Can anyone tell me why? > > Thanks > > > > > --m00nlight > > > > > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeffbrown.the at gmail.com Sun Mar 8 17:57:01 2015 From: jeffbrown.the at gmail.com (Jeffrey Brown) Date: Sun, 8 Mar 2015 10:57:01 -0700 Subject: [Haskell-beginners] Laziness to efficiently get one element from a set In-Reply-To: References: <87385gwep4.fsf@ilxwinb01.fritz.box> Message-ID: That is surprising. I would have expected an O(1) way to retrieve some value at random. On Sun, Mar 8, 2015 at 12:59 AM, Heinrich Apfelmus < apfelmus at quantentunnel.de> wrote: > Thomas Bach wrote: > >> Jeffrey Brown writes: >> >> head $ Data.Set.toList S. If I do that, am I correct that Haskell will >>> not try to convert all of S to a list; instead it will only convert >>> one element, and then return it, and leave the rest of the list >>> unevaluated? >>> >> >> This is how toList from Data.Set.Base is defined in containers-0.5.0: >> >> {-------------------------------------------------------------------- >> Lists >> --------------------------------------------------------------------} >> -- | /O(n)/. Convert the set to a list of elements. Subject to list >> fusion. >> toList :: Set a -> [a] >> toList = toAscList >> >> -- | /O(n)/. Convert the set to an ascending list of elements. Subject to >> list fusion. >> toAscList :: Set a -> [a] >> toAscList = foldr (:) [] >> >> The buzzword you are looking for is list fusion: >> >> http://stackoverflow.com/questions/10945429/haskell- >> list-fusion-where-is-it-needed >> > > Actually, I don't think that list fusion is appropriate here. The `foldr` > used in the definition of `toAscList` is from the `Foldable` type class, > and implemented specifically for the `Set` data type. It's not the usual > fold on lists. > > Jeffrey, if you want to pick a single element from a `Set`, I would > recommend the functions `findMin` or `findMax`. The former satisfies > > Data.Set.findMin = head . Data.Set.toList > > so you will get the same element as in your original approach. This time, > however, you can be sure that it takes O(log n) time, whereas in the > approach using `head`, it depends on the internals of the implementation of > `foldr` whether it will take time O(n) or O(log n) or something in between. > (In particular, it depends on how lazy the implementation of `foldr` for > `Set` is. See [1] for more on lazy evaluation in this / a similar context.) > > > [1]: https://hackhands.com/modular-code-lazy-evaluation-haskell/ > > > Best regards, > Heinrich Apfelmus > > -- > http://apfelmus.nfshost.com > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From bob at redivi.com Sun Mar 8 18:19:07 2015 From: bob at redivi.com (Bob Ippolito) Date: Sun, 8 Mar 2015 11:19:07 -0700 Subject: [Haskell-beginners] Laziness to efficiently get one element from a set In-Reply-To: References: <87385gwep4.fsf@ilxwinb01.fritz.box> Message-ID: It would be possible to return the value at the root of the tree in O(1) time, but there's no function for this and the constructor isn't exported so you can't implement it yourself. On Sun, Mar 8, 2015 at 10:57 AM, Jeffrey Brown wrote: > That is surprising. I would have expected an O(1) way to retrieve some > value at random. > > On Sun, Mar 8, 2015 at 12:59 AM, Heinrich Apfelmus < > apfelmus at quantentunnel.de> wrote: > >> Thomas Bach wrote: >> >>> Jeffrey Brown writes: >>> >>> head $ Data.Set.toList S. If I do that, am I correct that Haskell will >>>> not try to convert all of S to a list; instead it will only convert >>>> one element, and then return it, and leave the rest of the list >>>> unevaluated? >>>> >>> >>> This is how toList from Data.Set.Base is defined in containers-0.5.0: >>> >>> {-------------------------------------------------------------------- >>> Lists >>> --------------------------------------------------------------------} >>> -- | /O(n)/. Convert the set to a list of elements. Subject to list >>> fusion. >>> toList :: Set a -> [a] >>> toList = toAscList >>> >>> -- | /O(n)/. Convert the set to an ascending list of elements. Subject >>> to list fusion. >>> toAscList :: Set a -> [a] >>> toAscList = foldr (:) [] >>> >>> The buzzword you are looking for is list fusion: >>> >>> http://stackoverflow.com/questions/10945429/haskell- >>> list-fusion-where-is-it-needed >>> >> >> Actually, I don't think that list fusion is appropriate here. The `foldr` >> used in the definition of `toAscList` is from the `Foldable` type class, >> and implemented specifically for the `Set` data type. It's not the usual >> fold on lists. >> >> Jeffrey, if you want to pick a single element from a `Set`, I would >> recommend the functions `findMin` or `findMax`. The former satisfies >> >> Data.Set.findMin = head . Data.Set.toList >> >> so you will get the same element as in your original approach. This time, >> however, you can be sure that it takes O(log n) time, whereas in the >> approach using `head`, it depends on the internals of the implementation of >> `foldr` whether it will take time O(n) or O(log n) or something in between. >> (In particular, it depends on how lazy the implementation of `foldr` for >> `Set` is. See [1] for more on lazy evaluation in this / a similar context.) >> >> >> [1]: https://hackhands.com/modular-code-lazy-evaluation-haskell/ >> >> >> Best regards, >> Heinrich Apfelmus >> >> -- >> http://apfelmus.nfshost.com >> >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kalawatia_abhinav at yahoo.com Mon Mar 9 15:47:06 2015 From: kalawatia_abhinav at yahoo.com (Abhinav Kalawatia) Date: Mon, 9 Mar 2015 15:47:06 +0000 (UTC) Subject: [Haskell-beginners] Saving intermediate calculations Message-ID: <1367874770.1593552.1425916026462.JavaMail.yahoo@mail.yahoo.com> ? Hello, I?am facing a slight difficulty trying to?do something while saving intermediate calculations week ?? actual_?sales(a) ??? forecast(f) ?????????????? ??????? forecast(f) ???????????????????????????? forecast(f) ?1 ?????????? 20 ??????????????????????? ?f1 = a1 ???????????????????????????? f1 = 20 ?????????????????????????????????? f1 = 20 ?2 ?????????? 27 ??????????????????????? ?f2 = f1 + 0.5*(a1 - f1)??????? f2 = 20 +0.5(20-20) ????????????? ?f2 = 20 ?3 ?????????? 25 ??????????????????????? ?f3 = f2 +? 0.5*(a2-f2)?????????f3 = 20+0.5*(27-20)???????????? ? f3=23.5 ?4 ?????????? 22 When I execute?a function to achieve this?in Haskell, I get the forecast for the fourth period. Can I save the values for intermediate period(1..3) also? Please find my Haskell code below: a = 0.5 ipt = [20,27,25,22] avg :: [Double] -> Double avg (x:xs) = (a*x) + (1-a)*(avg xs) avg [] = 0 Could you please help me with this, thanking you in anticipation Regards,Abhinav -------------- next part -------------- An HTML attachment was scrubbed... URL: From charioteer7 at gmail.com Mon Mar 9 20:07:23 2015 From: charioteer7 at gmail.com (Geoffrey Bays) Date: Mon, 9 Mar 2015 16:07:23 -0400 Subject: [Haskell-beginners] GHC not buying what I am offering this afternoon Message-ID: My main function looks like this: main :: [IO()] main = do let stud1 = Student {name = "Geoff", average = -99.0, grades = [66,77,88]} let stud2 = Student {name = "Doug", average = -99.0, grades = [77,88,99]} let stud3 = Student {name = "Ron", average = -99.0, grades = [55,66,77]} let studList = [stud1,stud2] let newList = calcAvg studList [putStrLn $ show s | s <- newList] --putStrLn $ show (newList !! 0) --putStrLn $ show (newList !! 1) With this final line, putStrLn $ show (newList !! 0), the type IO () in the function declaration compiles fine. But with [putStrLn $ show s | s <- newList] as the final line, [IO ()] in the function declaration will not compile, I get this error: Couldn't match expected type `IO t0' with actual type `[IO ()]' What does the declared type need to be for a final line of: [putStrLn $ show s | s <- newList] ??? Thanks, Geoffrey -------------- next part -------------- An HTML attachment was scrubbed... URL: From joel.s.williamson at gmail.com Mon Mar 9 20:15:59 2015 From: joel.s.williamson at gmail.com (Joel Williamson) Date: Mon, 09 Mar 2015 20:15:59 +0000 Subject: [Haskell-beginners] GHC not buying what I am offering this afternoon References: Message-ID: main must have type IO a. Hoogle tells me that to convert [IO a] -> IO [a], you should use the function sequence. Try applying that to your final line. On Mon, 9 Mar 2015 16:07 Geoffrey Bays wrote: > My main function looks like this: > > main :: [IO()] > main = do > let stud1 = Student {name = "Geoff", average = -99.0, grades = > [66,77,88]} > let stud2 = Student {name = "Doug", average = -99.0, grades = > [77,88,99]} > let stud3 = Student {name = "Ron", average = -99.0, grades = > [55,66,77]} > let studList = [stud1,stud2] > let newList = calcAvg studList > [putStrLn $ show s | s <- newList] > --putStrLn $ show (newList !! 0) > --putStrLn $ show (newList !! 1) > > With this final line, putStrLn $ show (newList !! 0), the type IO () in > the function declaration compiles fine. > But with [putStrLn $ show s | s <- newList] as the final line, [IO ()] in > the function declaration will not compile, I get this error: > > Couldn't match expected type `IO t0' with actual type `[IO ()]' > > What does the declared type need to be for a final line of: > [putStrLn $ show s | s <- newList] ??? > > Thanks, > > Geoffrey > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From charioteer7 at gmail.com Mon Mar 9 20:25:02 2015 From: charioteer7 at gmail.com (Geoffrey Bays) Date: Mon, 9 Mar 2015 16:25:02 -0400 Subject: [Haskell-beginners] GHC not buying what I am offering this afternoon In-Reply-To: References: Message-ID: Thanks, Joel. Putting the type IO [()] in the main declaration and this as the final line of the main function does do the trick: sequence [putStrLn $ show s | s <- newList] But this is the kind of thing that makes Haskell types difficult for beginners to work with... Geoffrey On Mon, Mar 9, 2015 at 4:15 PM, Joel Williamson wrote: > main must have type IO a. Hoogle tells me that to convert [IO a] -> IO > [a], you should use the function sequence. Try applying that to your final > line. > > On Mon, 9 Mar 2015 16:07 Geoffrey Bays wrote: > >> My main function looks like this: >> >> main :: [IO()] >> main = do >> let stud1 = Student {name = "Geoff", average = -99.0, grades = >> [66,77,88]} >> let stud2 = Student {name = "Doug", average = -99.0, grades = >> [77,88,99]} >> let stud3 = Student {name = "Ron", average = -99.0, grades = >> [55,66,77]} >> let studList = [stud1,stud2] >> let newList = calcAvg studList >> [putStrLn $ show s | s <- newList] >> --putStrLn $ show (newList !! 0) >> --putStrLn $ show (newList !! 1) >> >> With this final line, putStrLn $ show (newList !! 0), the type IO () in >> the function declaration compiles fine. >> But with [putStrLn $ show s | s <- newList] as the final line, [IO ()] in >> the function declaration will not compile, I get this error: >> >> Couldn't match expected type `IO t0' with actual type `[IO ()]' >> >> What does the declared type need to be for a final line of: >> [putStrLn $ show s | s <- newList] ??? >> >> Thanks, >> >> Geoffrey >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From toad3k at gmail.com Mon Mar 9 20:37:59 2015 From: toad3k at gmail.com (David McBride) Date: Mon, 9 Mar 2015 16:37:59 -0400 Subject: [Haskell-beginners] GHC not buying what I am offering this afternoon In-Reply-To: References: Message-ID: There is a difference between IO [()] and IO () and [IO ()] A type of [IO ()] is a list of actions, none of which have actually been executed. A type of IO [()] is a single action that has executed and returned a bunch of nils. sequence is one way to combine a list of actions into a single action that returns a list of their results, but it might be better to try and separate the pure and impure part of that line of code: mapM putStrLn $ ([show s | s <- [1,2,3]] :: [String]) :: IO [()] The type annotations are for explanation only. Then use mapM_ if you do not want to save these nils for some reason (there are performance implications). On Mon, Mar 9, 2015 at 4:25 PM, Geoffrey Bays wrote: > Thanks, Joel. > > Putting the type IO [()] in the main declaration and this as the final > line of the main function does do the trick: > > sequence [putStrLn $ show s | s <- newList] > > But this is the kind of thing that makes Haskell types difficult for > beginners to work with... > > Geoffrey > > On Mon, Mar 9, 2015 at 4:15 PM, Joel Williamson < > joel.s.williamson at gmail.com> wrote: > >> main must have type IO a. Hoogle tells me that to convert [IO a] -> IO >> [a], you should use the function sequence. Try applying that to your final >> line. >> >> On Mon, 9 Mar 2015 16:07 Geoffrey Bays wrote: >> >>> My main function looks like this: >>> >>> main :: [IO()] >>> main = do >>> let stud1 = Student {name = "Geoff", average = -99.0, grades = >>> [66,77,88]} >>> let stud2 = Student {name = "Doug", average = -99.0, grades = >>> [77,88,99]} >>> let stud3 = Student {name = "Ron", average = -99.0, grades = >>> [55,66,77]} >>> let studList = [stud1,stud2] >>> let newList = calcAvg studList >>> [putStrLn $ show s | s <- newList] >>> --putStrLn $ show (newList !! 0) >>> --putStrLn $ show (newList !! 1) >>> >>> With this final line, putStrLn $ show (newList !! 0), the type IO () in >>> the function declaration compiles fine. >>> But with [putStrLn $ show s | s <- newList] as the final line, [IO ()] >>> in the function declaration will not compile, I get this error: >>> >>> Couldn't match expected type `IO t0' with actual type `[IO ()]' >>> >>> What does the declared type need to be for a final line of: >>> [putStrLn $ show s | s <- newList] ??? >>> >>> Thanks, >>> >>> Geoffrey >>> >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From joel.s.williamson at gmail.com Mon Mar 9 20:39:37 2015 From: joel.s.williamson at gmail.com (Joel Williamson) Date: Mon, 9 Mar 2015 16:39:37 -0400 Subject: [Haskell-beginners] GHC not buying what I am offering this afternoon In-Reply-To: References: Message-ID: sequence will get the types to match up, but a more elegant solution would be to get every line into a single string, then print that. putStrLn $ unlines $ map show newList I agree that getting the types to line up can be a nuisance, and with such small programs it doesn't bring much of an advantage. Ultimately, if you want side-effects to be reflected in the type system, there will be times you have to do a bit of extra work to satisfy the type checker. Learning to write well-typed code is much easier in this context, where everything has a fairly concrete type and there is lots of documentation, than having to learn it later when you have weird types coming from 3 different libraries and are facing a problem no one else has had. I would recommend getting very comfortable with GHCi and Hoogle. If you haven't already, add a hoogle prompt to GHCi by pasting something like :def hoogle \str -> return $ ":! hoogle --count=15 \"" ++ str ++ "\"" in your ghci.conf. This will allow you to easily search for functions of a given type. Typing :hoogle [IO a] -> IO [a] returned all the information needed to answer your question. On Mon, Mar 9, 2015 at 4:25 PM, Geoffrey Bays wrote: > Thanks, Joel. > > Putting the type IO [()] in the main declaration and this as the final line > of the main function does do the trick: > > sequence [putStrLn $ show s | s <- newList] > > But this is the kind of thing that makes Haskell types difficult for > beginners to work with... > > Geoffrey > > On Mon, Mar 9, 2015 at 4:15 PM, Joel Williamson > wrote: >> >> main must have type IO a. Hoogle tells me that to convert [IO a] -> IO >> [a], you should use the function sequence. Try applying that to your final >> line. >> >> >> On Mon, 9 Mar 2015 16:07 Geoffrey Bays wrote: >>> >>> My main function looks like this: >>> >>> main :: [IO()] >>> main = do >>> let stud1 = Student {name = "Geoff", average = -99.0, grades = >>> [66,77,88]} >>> let stud2 = Student {name = "Doug", average = -99.0, grades = >>> [77,88,99]} >>> let stud3 = Student {name = "Ron", average = -99.0, grades = >>> [55,66,77]} >>> let studList = [stud1,stud2] >>> let newList = calcAvg studList >>> [putStrLn $ show s | s <- newList] >>> --putStrLn $ show (newList !! 0) >>> --putStrLn $ show (newList !! 1) >>> >>> With this final line, putStrLn $ show (newList !! 0), the type IO () in >>> the function declaration compiles fine. >>> But with [putStrLn $ show s | s <- newList] as the final line, [IO ()] in >>> the function declaration will not compile, I get this error: >>> >>> Couldn't match expected type `IO t0' with actual type `[IO ()]' >>> >>> What does the declared type need to be for a final line of: >>> [putStrLn $ show s | s <- newList] ??? >>> >>> Thanks, >>> >>> Geoffrey >>> >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > From apfelmus at quantentunnel.de Mon Mar 9 23:15:20 2015 From: apfelmus at quantentunnel.de (Heinrich Apfelmus) Date: Tue, 10 Mar 2015 00:15:20 +0100 Subject: [Haskell-beginners] Avoiding stack space overflow In-Reply-To: References: <20150126121926.GA1981@golay.schaathun.net> <20150126164517.GA27771@golay.schaathun.net> Message-ID: Bob Ippolito wrote: > Here are my go-to resources for Haskell's evaluation: > > http://chimera.labs.oreilly.com/books/1230000000929/ch02.html#sec_par-eval-whnf > https://hackhands.com/lazy-evaluation-works-haskell/ I just wanted to mention that I have now expanded the latter resource. It is best reached from the following URL: https://hackhands.com/guide-lazy-evaluation-haskell/ Best regards, Heinrich Apfelmus -- http://apfelmus.nfshost.com From sumit.sahrawat.apm13 at iitbhu.ac.in Tue Mar 10 05:26:52 2015 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Tue, 10 Mar 2015 10:56:52 +0530 Subject: [Haskell-beginners] GHC not buying what I am offering this afternoon In-Reply-To: References: Message-ID: Just like sequence, there is also a function sequence_ that you might want to use. sequence_ :: Monad m => [m a] -> m () -- for m = IO, sequence_ :: [IO a] -> IO () sequence_ lst = do sequence lst return () -- also, mapM and mapM_ are useful too mapM f = sequence . map f -- retains results mapM_ f = sequence_ . map f -- ignores results -- Some use cases ghci> sequence [print 2, print 3] 2 3 [(),()] -- The results, each print is of type IO (), i.e does IO and produces () ghci> mapM print [2,3] -- same as above ghci> mapM_ print [2,3] -- same as above, but without results (or result of type unit, i.e ()) On 10 March 2015 at 02:09, Joel Williamson wrote: > sequence will get the types to match up, but a more elegant solution > would be to get every line into a single string, then print that. > > putStrLn $ unlines $ map show newList > > I agree that getting the types to line up can be a nuisance, and with > such small programs it doesn't bring much of an advantage. Ultimately, > if you want side-effects to be reflected in the type system, there > will be times you have to do a bit of extra work to satisfy the type > checker. Learning to write well-typed code is much easier in this > context, where everything has a fairly concrete type and there is lots > of documentation, than having to learn it later when you have weird > types coming from 3 different libraries and are facing a problem no > one else has had. I would recommend getting very comfortable with GHCi > and Hoogle. > > If you haven't already, add a hoogle prompt to GHCi by pasting something > like > :def hoogle \str -> return $ ":! hoogle --count=15 \"" ++ str ++ "\"" > in your ghci.conf. This will allow you to easily search for functions > of a given type. Typing > :hoogle [IO a] -> IO [a] > returned all the information needed to answer your question. > > > On Mon, Mar 9, 2015 at 4:25 PM, Geoffrey Bays > wrote: > > Thanks, Joel. > > > > Putting the type IO [()] in the main declaration and this as the final > line > > of the main function does do the trick: > > > > sequence [putStrLn $ show s | s <- newList] > > > > But this is the kind of thing that makes Haskell types difficult for > > beginners to work with... > > > > Geoffrey > > > > On Mon, Mar 9, 2015 at 4:15 PM, Joel Williamson > > wrote: > >> > >> main must have type IO a. Hoogle tells me that to convert [IO a] -> IO > >> [a], you should use the function sequence. Try applying that to your > final > >> line. > >> > >> > >> On Mon, 9 Mar 2015 16:07 Geoffrey Bays wrote: > >>> > >>> My main function looks like this: > >>> > >>> main :: [IO()] > >>> main = do > >>> let stud1 = Student {name = "Geoff", average = -99.0, grades = > >>> [66,77,88]} > >>> let stud2 = Student {name = "Doug", average = -99.0, grades = > >>> [77,88,99]} > >>> let stud3 = Student {name = "Ron", average = -99.0, grades = > >>> [55,66,77]} > >>> let studList = [stud1,stud2] > >>> let newList = calcAvg studList > >>> [putStrLn $ show s | s <- newList] > >>> --putStrLn $ show (newList !! 0) > >>> --putStrLn $ show (newList !! 1) > >>> > >>> With this final line, putStrLn $ show (newList !! 0), the type IO () in > >>> the function declaration compiles fine. > >>> But with [putStrLn $ show s | s <- newList] as the final line, [IO ()] > in > >>> the function declaration will not compile, I get this error: > >>> > >>> Couldn't match expected type `IO t0' with actual type `[IO ()]' > >>> > >>> What does the declared type need to be for a final line of: > >>> [putStrLn $ show s | s <- newList] ??? > >>> > >>> Thanks, > >>> > >>> Geoffrey > >>> > >>> _______________________________________________ > >>> Beginners mailing list > >>> Beginners at haskell.org > >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > >> > >> > >> _______________________________________________ > >> Beginners mailing list > >> Beginners at haskell.org > >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > >> > > > > > > _______________________________________________ > > Beginners mailing list > > Beginners at haskell.org > > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -- Regards Sumit Sahrawat -------------- next part -------------- An HTML attachment was scrubbed... URL: From bob at redivi.com Tue Mar 10 06:03:49 2015 From: bob at redivi.com (Bob Ippolito) Date: Mon, 9 Mar 2015 23:03:49 -0700 Subject: [Haskell-beginners] Avoiding stack space overflow In-Reply-To: References: <20150126121926.GA1981@golay.schaathun.net> <20150126164517.GA27771@golay.schaathun.net> Message-ID: On Mon, Mar 9, 2015 at 4:15 PM, Heinrich Apfelmus wrote: > Bob Ippolito wrote: > >> Here are my go-to resources for Haskell's evaluation: >> >> http://chimera.labs.oreilly.com/books/1230000000929/ch02. >> html#sec_par-eval-whnf >> https://hackhands.com/lazy-evaluation-works-haskell/ >> > > I just wanted to mention that I have now expanded the latter resource. It > is best reached from the following URL: > > https://hackhands.com/guide-lazy-evaluation-haskell/ Thank you, this is great! Perhaps you could also link to this from the top and/or bottom of each individual article to make them all more discoverable from existing links? -bob -------------- next part -------------- An HTML attachment was scrubbed... URL: From apfelmus at quantentunnel.de Tue Mar 10 09:49:08 2015 From: apfelmus at quantentunnel.de (Heinrich Apfelmus) Date: Tue, 10 Mar 2015 10:49:08 +0100 Subject: [Haskell-beginners] Avoiding stack space overflow In-Reply-To: References: <20150126121926.GA1981@golay.schaathun.net> <20150126164517.GA27771@golay.schaathun.net> Message-ID: Bob Ippolito wrote: > On Mon, Mar 9, 2015 at 4:15 PM, Heinrich Apfelmus > wrote: > >> Bob Ippolito wrote: >> >>> Here are my go-to resources for Haskell's evaluation: >>> >>> http://chimera.labs.oreilly.com/books/1230000000929/ch02. >>> html#sec_par-eval-whnf >>> https://hackhands.com/lazy-evaluation-works-haskell/ >>> >> I just wanted to mention that I have now expanded the latter resource. It >> is best reached from the following URL: >> >> https://hackhands.com/guide-lazy-evaluation-haskell/ > > > Thank you, this is great! Perhaps you could also link to this from the top > and/or bottom of each individual article to make them all more discoverable > from existing links? Good idea! I have added a link at the top of each post. Does this work as intended? Best regards, Heinrich Apfelmus -- http://apfelmus.nfshost.com From animeshsaxena at icloud.com Tue Mar 10 13:43:33 2015 From: animeshsaxena at icloud.com (Animesh Saxena) Date: Tue, 10 Mar 2015 21:43:33 +0800 Subject: [Haskell-beginners] Avoiding stack space overflow In-Reply-To: References: <20150126121926.GA1981@golay.schaathun.net> <20150126164517.GA27771@golay.schaathun.net> Message-ID: This is really nice stuff. Thanks Animesh Sent from my iPhone > On 10-Mar-2015, at 5:49 pm, Heinrich Apfelmus wrote: > > Bob Ippolito wrote: >> On Mon, Mar 9, 2015 at 4:15 PM, Heinrich Apfelmus >> wrote: >>> Bob Ippolito wrote: >>> >>>> Here are my go-to resources for Haskell's evaluation: >>>> >>>> http://chimera.labs.oreilly.com/books/1230000000929/ch02. >>>> html#sec_par-eval-whnf >>>> https://hackhands.com/lazy-evaluation-works-haskell/ >>> I just wanted to mention that I have now expanded the latter resource. It >>> is best reached from the following URL: >>> >>> https://hackhands.com/guide-lazy-evaluation-haskell/ >> Thank you, this is great! Perhaps you could also link to this from the top >> and/or bottom of each individual article to make them all more discoverable >> from existing links? > > Good idea! I have added a link at the top of each post. Does this work as intended? > > > Best regards, > Heinrich Apfelmus > > -- > http://apfelmus.nfshost.com > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From bob at redivi.com Tue Mar 10 20:54:17 2015 From: bob at redivi.com (Bob Ippolito) Date: Tue, 10 Mar 2015 13:54:17 -0700 Subject: [Haskell-beginners] Avoiding stack space overflow In-Reply-To: References: <20150126121926.GA1981@golay.schaathun.net> <20150126164517.GA27771@golay.schaathun.net> Message-ID: On Tue, Mar 10, 2015 at 2:49 AM, Heinrich Apfelmus < apfelmus at quantentunnel.de> wrote: > Bob Ippolito wrote: > >> On Mon, Mar 9, 2015 at 4:15 PM, Heinrich Apfelmus < >> apfelmus at quantentunnel.de >> >>> wrote: >>> >> >> Bob Ippolito wrote: >>> >>> Here are my go-to resources for Haskell's evaluation: >>>> >>>> http://chimera.labs.oreilly.com/books/1230000000929/ch02. >>>> html#sec_par-eval-whnf >>>> https://hackhands.com/lazy-evaluation-works-haskell/ >>>> >>>> I just wanted to mention that I have now expanded the latter resource. >>> It >>> is best reached from the following URL: >>> >>> https://hackhands.com/guide-lazy-evaluation-haskell/ >>> >> >> >> Thank you, this is great! Perhaps you could also link to this from the top >> and/or bottom of each individual article to make them all more >> discoverable >> from existing links? >> > > Good idea! I have added a link at the top of each post. Does this work as > intended? Absolutely, works perfectly! -bob -------------- next part -------------- An HTML attachment was scrubbed... URL: From hjgtuyl at chello.nl Wed Mar 11 00:05:10 2015 From: hjgtuyl at chello.nl (Henk-Jan van Tuyl) Date: Wed, 11 Mar 2015 01:05:10 +0100 Subject: [Haskell-beginners] Saving intermediate calculations In-Reply-To: <1367874770.1593552.1425916026462.JavaMail.yahoo@mail.yahoo.com> References: <1367874770.1593552.1425916026462.JavaMail.yahoo@mail.yahoo.com> Message-ID: On Mon, 09 Mar 2015 16:47:06 +0100, Abhinav Kalawatia wrote: : > week actual_ sales(a) forecast(f) > forecast(f) forecast(f) > 1 20 f1 = a1 > f1 = 20 > f1 = 20 > 2 27 f2 = f1 + 0.5*(a1 - f1) > f2 = 20 +0.5(20-20) f2 = 20 > 3 25 f3 = f2 + 0.5*(a2-f2) > f3 = 20+0.5*(27-20) f3=23.5 > 4 22 > > > When I execute a function to achieve this in Haskell, I get the forecast > for the fourth period. Can I save the values for intermediate > period(1..3) also? > > > Please find my Haskell code below: > a = 0.5 > ipt = [20,27,25,22] > avg :: [Double] -> Double > avg (x:xs) = (a*x) + (1-a)*(avg xs) > avg [] = 0 : It looks to me, that mapAccumL[0] might do the trick (I haven't studied this in detail). Regards, Henk-Jan van Tuyl [0] http://haddocks.fpcomplete.com/fp/7.8/20140916-162/base/Data-List.html#v:mapAccumL -- Folding at home What if you could share your unused computer power to help find a cure? In just 5 minutes you can join the world's biggest networked computer and get us closer sooner. Watch the video. http://folding.stanford.edu/ http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html Haskell programming -- From hengruo.z at gmail.com Wed Mar 11 13:21:23 2015 From: hengruo.z at gmail.com (Zhang Hengruo) Date: Wed, 11 Mar 2015 21:21:23 +0800 Subject: [Haskell-beginners] What's the type of function "abs"? Message-ID: I'm a newbie, knowing a little about Haskell, and hope my question isn't very silly... ===================================================================== My absolute value function looks like this: abs2 :: Num a => a -> a abs2 n = if n >= 0 then n else 0 - n GHCi tells me that I should add Ord type class to its definition. Well, it's true. It has used relational operators and Num isn't a subclass of Ord. However, when I input ":t abs" in GHCi, the interpreter shows "abs :: Num a => a -> a". I read GHC/Num.lhs and find that abs is defined as "abs :: a -> a" and has no concrete content. So I think the abs function is written in C as a module to implement directly and the type of abs just follows its class GHC.Num. Is it right? Or there are any other reasons? Thanks, Hengruo -------------- next part -------------- An HTML attachment was scrubbed... URL: From raabe at froglogic.com Wed Mar 11 13:28:05 2015 From: raabe at froglogic.com (Frerich Raabe) Date: Wed, 11 Mar 2015 14:28:05 +0100 Subject: [Haskell-beginners] =?utf-8?q?What=27s_the_type_of_function_=22ab?= =?utf-8?b?cyI/?= In-Reply-To: References: Message-ID: <71d09d762202621a09390f2b33f4f6cf@roundcube.froglogic.com> Hi, On 2015-03-11 14:21, Zhang Hengruo wrote: > My absolute value function looks like this: > > abs2 :: Num a => a -> a > abs2 n = if n >= 0 then n else 0 - n > > GHCi tells me that I should add Ord type class to its definition. Well, it's > true. It has used relational operators and Num isn't a subclass > of Ord. > However, when I input ":t abs" in GHCi, the interpreter shows "abs :: Num a > => a -> a". I read GHC/Num.lhs and find that abs is defined as > "abs :: a -> a" and has no concrete content. So I think the abs function is > written in C as a module to implement directly and the type of abs > just follows its class GHC.Num. Is it right? Or there are any other reasons? 'abs' is a function defined on the 'Num' class, i.e. any instance of 'Num' (such as 'Num Int') may define 'abs' as it pleases. See http://hackage.haskell.org/package/base-4.7.0.2/docs/src/GHC-Num.html#abs for a few instantiations of the 'Num' class. In particular, concrete instances of the class know the actual type of 'a'. For instance, the definition of 'Num Int' could actually use '>=' because there's indeed an Ord instance for Int. In other cases, e.g. 'Num Word', 'abs' is just the identity function, i.e. 'abs x = x' since there are no non-positive Word values. -- Frerich Raabe - raabe at froglogic.com www.froglogic.com - Multi-Platform GUI Testing From dani at dpwright.com Wed Mar 11 13:30:45 2015 From: dani at dpwright.com (Daniel P. Wright) Date: Wed, 11 Mar 2015 22:30:45 +0900 Subject: [Haskell-beginners] What's the type of function "abs"? In-Reply-To: References: Message-ID: <924EF1DE-B9DA-45DE-89CE-2623022FF22C@dpwright.com> One nice thing about haskell is that the source to most things is available on hackage. If you look at abs, here: https://hackage.haskell.org/package/base-4.7.0.2/docs/src/GHC-Num.html#abs You will see two things: 1) abs is actually part of the Num typeclass, so can be defined differently for the different numerical types 2) the definition for Int is similar to yours: abs n = if n `geInt` 0 then n else negate n Notice `geInt` is just an int-specific (>=) operator. Because we're defining an instance we know the concrete type we're dealing with (the type is Int -> Int by this point, rather than a -> a), so we don't need to make use of Ord in this case. 11 Mar 2015 22:21?Zhang Hengruo ??????: > I'm a newbie, knowing a little about Haskell, and hope my question isn't very silly... > ===================================================================== > My absolute value function looks like this: > > abs2 :: Num a => a -> a > abs2 n = if n >= 0 then n else 0 - n > > GHCi tells me that I should add Ord type class to its definition. Well, it's true. It has used relational operators and Num isn't a subclass of Ord. > However, when I input ":t abs" in GHCi, the interpreter shows "abs :: Num a => a -> a". I read GHC/Num.lhs and find that abs is defined as "abs :: a -> a" and has no concrete content. So I think the abs function is written in C as a module to implement directly and the type of abs just follows its class GHC.Num. Is it right? Or there are any other reasons? > > Thanks, > > Hengruo > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: From hengruo.z at gmail.com Wed Mar 11 14:08:18 2015 From: hengruo.z at gmail.com (Zhang Hengruo) Date: Wed, 11 Mar 2015 22:08:18 +0800 Subject: [Haskell-beginners] What's the type of function "abs"? In-Reply-To: <924EF1DE-B9DA-45DE-89CE-2623022FF22C@dpwright.com> References: <924EF1DE-B9DA-45DE-89CE-2623022FF22C@dpwright.com> Message-ID: Oh! Thank you very much! I took notice of instances of Num just now... You two are so kind! 2015-03-11 21:30 GMT+08:00 Daniel P. Wright : > One nice thing about haskell is that the source to most things is > available on hackage. If you look at abs, here: > > https://hackage.haskell.org/package/base-4.7.0.2/docs/src/GHC-Num.html#abs > > You will see two things: > > 1) abs is actually part of the Num typeclass, so can be defined > differently for the different numerical types > 2) the definition for Int is similar to yours: > > abs n = if n `geInt` 0 then n else negate n > > > Notice `geInt` is just an int-specific (>=) operator. Because we're > defining an instance we know the concrete type we're dealing with (the type > is Int -> Int by this point, rather than a -> a), so we don't need to make > use of Ord in this case. > > > > 11 Mar 2015 22:21?Zhang Hengruo ??????: > > I'm a newbie, knowing a little about Haskell, and hope my question isn't > very silly... > ===================================================================== > My absolute value function looks like this: > > abs2 :: Num a => a -> a > abs2 n = if n >= 0 then n else 0 - n > > GHCi tells me that I should add Ord type class to its definition. Well, > it's true. It has used relational operators and Num isn't a subclass of Ord. > However, when I input ":t abs" in GHCi, the interpreter shows "abs :: Num > a => a -> a". I read GHC/Num.lhs and find that abs is defined as "abs :: a > -> a" and has no concrete content. So I think the abs function is written > in C as a module to implement directly and the type of abs just follows its > class GHC.Num. Is it right? Or there are any other reasons? > > Thanks, > > Hengruo > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sumit.sahrawat.apm13 at iitbhu.ac.in Wed Mar 11 21:45:03 2015 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Thu, 12 Mar 2015 03:15:03 +0530 Subject: [Haskell-beginners] Mathematical functions with multiple arguments Message-ID: Hi everybody, I have a function of type plot :: ([Double] -> Double) -- A function to plot -> [(Double, Double)] -- Range for all arguments -> IO () I want to enforce the fact that ranges for all arguments should be provided. Is there a way to make the type system enforce it? -- Regards Sumit Sahrawat -------------- next part -------------- An HTML attachment was scrubbed... URL: From sumit.sahrawat.apm13 at iitbhu.ac.in Wed Mar 11 21:58:51 2015 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Thu, 12 Mar 2015 03:28:51 +0530 Subject: [Haskell-beginners] [Haskell-cafe] Mathematical functions with multiple arguments In-Reply-To: References: Message-ID: I was wondering whether it was possible using fixed-vector, ut dependent types seem to be a new thing I can experiment with. Thanks for the quick reply. On 12 March 2015 at 03:26, Adam Bergmark wrote: > If I understand you correctly you seem to want dependent types, this > article uses the same example you need, promoting the length of a > vector/list to the type level: > https://www.fpcomplete.com/user/konn/prove-your-haskell-for-great-safety/dependent-types-in-haskell > > You'd end up with `plot :: (Vector n Double -> Double) -> Vector n > (Double, Double) -> IO ()' where `n' is the length of the vector. > > HTH, > Adam > > > On Wed, Mar 11, 2015 at 10:45 PM, Sumit Sahrawat, Maths & Computing, IIT > (BHU) wrote: > >> Hi everybody, >> >> I have a function of type >> >> plot :: ([Double] -> Double) -- A function to plot >> -> [(Double, Double)] -- Range for all arguments >> -> IO () >> >> I want to enforce the fact that ranges for all arguments should be >> provided. >> Is there a way to make the type system enforce it? >> >> -- >> Regards >> >> Sumit Sahrawat >> >> _______________________________________________ >> Haskell-Cafe mailing list >> Haskell-Cafe at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe >> >> > -- Regards Sumit Sahrawat -------------- next part -------------- An HTML attachment was scrubbed... URL: From sumit.sahrawat.apm13 at iitbhu.ac.in Wed Mar 11 23:16:42 2015 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Thu, 12 Mar 2015 04:46:42 +0530 Subject: [Haskell-beginners] [Haskell-cafe] Mathematical functions with multiple arguments In-Reply-To: References: Message-ID: The fixed-vector package uses a similar technique. The only trouble I'm having is with converting Vec v (Double, Double) to [(Double, Double)] for further use. I don't want to change all the code, but only the part where the user provides me with arguments. I'll keep looking into it. Thanks for the help. On 12 March 2015 at 04:44, David Feuer wrote: > There are a lot of ways to do this sort of thing, and which one you choose > will depend on exactly what you're trying to do. For example, you can write > something vaguely like > > data Nat = Z | S Nat > data SL (n :: Nat) a where > Nil :: SL Z > Cons :: a -> SL n a -> SL (S n) a > > plot :: forall (n::Nat) . (SL n Double -> Double) -> > SL n (Double, Double) -> IO () > On Mar 11, 2015 5:45 PM, "Sumit Sahrawat, Maths & Computing, IIT (BHU)" < > sumit.sahrawat.apm13 at iitbhu.ac.in> wrote: > >> Hi everybody, >> >> I have a function of type >> >> plot :: ([Double] -> Double) -- A function to plot >> -> [(Double, Double)] -- Range for all arguments >> -> IO () >> >> I want to enforce the fact that ranges for all arguments should be >> provided. >> Is there a way to make the type system enforce it? >> >> -- >> Regards >> >> Sumit Sahrawat >> >> _______________________________________________ >> Haskell-Cafe mailing list >> Haskell-Cafe at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe >> >> -- Regards Sumit Sahrawat -------------- next part -------------- An HTML attachment was scrubbed... URL: From sumit.sahrawat.apm13 at iitbhu.ac.in Thu Mar 12 00:19:25 2015 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Thu, 12 Mar 2015 05:49:25 +0530 Subject: [Haskell-beginners] [Haskell-cafe] Mathematical functions with multiple arguments In-Reply-To: References: Message-ID: It's done. fixed-vector provides many implementations for Vec. The one I was using (Primitive) requires primitive constraint on data types. I shifted to Unboxed ones, and now it's working. This means that I am able to use toList with Vec v (Double, Double), which was previously complaining of missing constraints. Also, I'll slowly convert the whole thing. I wanted to just see if it works initially. Thanks, once again. On 12 March 2015 at 04:58, David Feuer wrote: > I'd urge you to *try* to maintain that safety throughout, but you can try > something like this if necessary (I'm not at my computer, so I can't test > it): > > {-#LANGUAGE FlexibleContexts, FlexibleInstances #-} > instance Foldable (SL Z) where > foldr _ n Nil = n > > instance Foldable (SL n) => Foldable (SL (S n)) where > foldr c n (Cons x xs) = c x (foldr c n xs) > > In fact, I would expect whatever package you're looking at to offer this. > Then you can just use Data.Foldable.toList. > On Mar 11, 2015 7:16 PM, "Sumit Sahrawat, Maths & Computing, IIT (BHU)" < > sumit.sahrawat.apm13 at iitbhu.ac.in> wrote: > >> The fixed-vector package uses a similar technique. The only trouble I'm >> having is with converting Vec v (Double, Double) to [(Double, Double)] for >> further use. I don't want to change all the code, but only the part where >> the user provides me with arguments. >> >> I'll keep looking into it. Thanks for the help. >> >> On 12 March 2015 at 04:44, David Feuer wrote: >> >>> There are a lot of ways to do this sort of thing, and which one you >>> choose will depend on exactly what you're trying to do. For example, you >>> can write something vaguely like >>> >>> data Nat = Z | S Nat >>> data SL (n :: Nat) a where >>> Nil :: SL Z >>> Cons :: a -> SL n a -> SL (S n) a >>> >>> plot :: forall (n::Nat) . (SL n Double -> Double) -> >>> SL n (Double, Double) -> IO () >>> On Mar 11, 2015 5:45 PM, "Sumit Sahrawat, Maths & Computing, IIT (BHU)" < >>> sumit.sahrawat.apm13 at iitbhu.ac.in> wrote: >>> >>>> Hi everybody, >>>> >>>> I have a function of type >>>> >>>> plot :: ([Double] -> Double) -- A function to plot >>>> -> [(Double, Double)] -- Range for all arguments >>>> -> IO () >>>> >>>> I want to enforce the fact that ranges for all arguments should be >>>> provided. >>>> Is there a way to make the type system enforce it? >>>> >>>> -- >>>> Regards >>>> >>>> Sumit Sahrawat >>>> >>>> _______________________________________________ >>>> Haskell-Cafe mailing list >>>> Haskell-Cafe at haskell.org >>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe >>>> >>>> >> >> >> -- >> Regards >> >> Sumit Sahrawat >> > -- Regards Sumit Sahrawat -------------- next part -------------- An HTML attachment was scrubbed... URL: From k-bx at k-bx.com Thu Mar 12 07:05:05 2015 From: k-bx at k-bx.com (Konstantine Rybnikov) Date: Thu, 12 Mar 2015 09:05:05 +0200 Subject: [Haskell-beginners] [Haskell-cafe] Mathematical functions with multiple arguments In-Reply-To: References: Message-ID: Is `Data.Vector.Fixed.toList` is what you're looking for? On Thu, Mar 12, 2015 at 1:16 AM, Sumit Sahrawat, Maths & Computing, IIT (BHU) wrote: > The fixed-vector package uses a similar technique. The only trouble I'm > having is with converting Vec v (Double, Double) to [(Double, Double)] for > further use. I don't want to change all the code, but only the part where > the user provides me with arguments. > > I'll keep looking into it. Thanks for the help. > > On 12 March 2015 at 04:44, David Feuer wrote: > >> There are a lot of ways to do this sort of thing, and which one you >> choose will depend on exactly what you're trying to do. For example, you >> can write something vaguely like >> >> data Nat = Z | S Nat >> data SL (n :: Nat) a where >> Nil :: SL Z >> Cons :: a -> SL n a -> SL (S n) a >> >> plot :: forall (n::Nat) . (SL n Double -> Double) -> >> SL n (Double, Double) -> IO () >> On Mar 11, 2015 5:45 PM, "Sumit Sahrawat, Maths & Computing, IIT (BHU)" < >> sumit.sahrawat.apm13 at iitbhu.ac.in> wrote: >> >>> Hi everybody, >>> >>> I have a function of type >>> >>> plot :: ([Double] -> Double) -- A function to plot >>> -> [(Double, Double)] -- Range for all arguments >>> -> IO () >>> >>> I want to enforce the fact that ranges for all arguments should be >>> provided. >>> Is there a way to make the type system enforce it? >>> >>> -- >>> Regards >>> >>> Sumit Sahrawat >>> >>> _______________________________________________ >>> Haskell-Cafe mailing list >>> Haskell-Cafe at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe >>> >>> > > > -- > Regards > > Sumit Sahrawat > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sumit.sahrawat.apm13 at iitbhu.ac.in Thu Mar 12 08:42:29 2015 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Thu, 12 Mar 2015 14:12:29 +0530 Subject: [Haskell-beginners] [Haskell-cafe] Mathematical functions with multiple arguments In-Reply-To: References: Message-ID: Yeah, Data.Vector.Fixed.toList worked. I had found it previously, but it didn't work for Vec imported from Data.Fixed.Vector.Primitive (as (Double, Double) doesn't have a Prim instance). Then I had to switch to Data.Fixed.Vector.Unboxed, and it works now. Also, those shingles look interesting too. Thanks everybody. On 12 March 2015 at 12:35, Konstantine Rybnikov wrote: > Is `Data.Vector.Fixed.toList` is what you're looking for? > > On Thu, Mar 12, 2015 at 1:16 AM, Sumit Sahrawat, Maths & Computing, IIT > (BHU) wrote: > >> The fixed-vector package uses a similar technique. The only trouble I'm >> having is with converting Vec v (Double, Double) to [(Double, Double)] for >> further use. I don't want to change all the code, but only the part where >> the user provides me with arguments. >> >> I'll keep looking into it. Thanks for the help. >> >> On 12 March 2015 at 04:44, David Feuer wrote: >> >>> There are a lot of ways to do this sort of thing, and which one you >>> choose will depend on exactly what you're trying to do. For example, you >>> can write something vaguely like >>> >>> data Nat = Z | S Nat >>> data SL (n :: Nat) a where >>> Nil :: SL Z >>> Cons :: a -> SL n a -> SL (S n) a >>> >>> plot :: forall (n::Nat) . (SL n Double -> Double) -> >>> SL n (Double, Double) -> IO () >>> On Mar 11, 2015 5:45 PM, "Sumit Sahrawat, Maths & Computing, IIT (BHU)" < >>> sumit.sahrawat.apm13 at iitbhu.ac.in> wrote: >>> >>>> Hi everybody, >>>> >>>> I have a function of type >>>> >>>> plot :: ([Double] -> Double) -- A function to plot >>>> -> [(Double, Double)] -- Range for all arguments >>>> -> IO () >>>> >>>> I want to enforce the fact that ranges for all arguments should be >>>> provided. >>>> Is there a way to make the type system enforce it? >>>> >>>> -- >>>> Regards >>>> >>>> Sumit Sahrawat >>>> >>>> _______________________________________________ >>>> Haskell-Cafe mailing list >>>> Haskell-Cafe at haskell.org >>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe >>>> >>>> >> >> >> -- >> Regards >> >> Sumit Sahrawat >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> > -- Regards Sumit Sahrawat -------------- next part -------------- An HTML attachment was scrubbed... URL: From twashing at gmail.com Thu Mar 12 23:02:12 2015 From: twashing at gmail.com (Timothy Washington) Date: Thu, 12 Mar 2015 19:02:12 -0400 Subject: [Haskell-beginners] Dipping Toes Into Haskell Message-ID: To get started, I'm trying to implement a simple *tictactoe* game. And I would like to be able to represent a Piece on the board, as either the string "X" or "O". This is what I have so far. module Main where data Piece = X | O type Row = [Piece] type Board = [Row] -- put an X or O in a position move :: Board -> Piece -> Board move board piece = board -- check win vertically -- check win horizontally -- check win diagonally main :: IO () main = putStrLn "Hello World" *A)* Now, I'd like to be able to *load code interactively*, preferably within emacs. However I don't have access to my types with *ghci* or *ghc-mod (Interactive-Haskell)*. In either case, this call fails with the below error. let p = Piece X :20:9-13: Not in scope: data constructor `Piece' *B)* And how do I make a *custom datatype* that's one of two strings (enumeration of either "X" or "O"). Cabal builds and runs the abouve code, so I know it can compile. But I'm confused as to where X or O is defined, and how I would supply it as an input. *C)* Finally, how do we update nested lists in Haskell. I want the move function to take a Board, Piece, and Position, and return a Board. I see some results from Hoogle . Is this where Lenses or Zippers come into play? Thanks Tim Washington Interruptsoftware.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From sumit.sahrawat.apm13 at iitbhu.ac.in Thu Mar 12 23:50:16 2015 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Fri, 13 Mar 2015 05:20:16 +0530 Subject: [Haskell-beginners] Dipping Toes Into Haskell In-Reply-To: References: Message-ID: data Piece = X | O means that X and O are constants, having data type 'Piece'. In other words, you directly use X and O instead of Piece X and Piece O. Piece is a type, and X and O are constructors (or simply the two possible values). A good similar example is the Bool type, data Bool = False | True -- Two possible values, i.e. False and True For more info, take a look here: http://en.wikibooks.org/wiki/Haskell/Type_declarations Also, to make life easier, you might want to use: data Piece = X | O deriving Show -- Make this type showable With this, you will be able to use 'print' with elements of this datatype. For a tutorial on setting up emacs, take a look here: https://github.com/serras/emacs-haskell-tutorial/blob/master/tutorial.md For updating nested lists, you have to create a function that takes two numbers (the positions) and iterates over the whole structure, just updating the required position. While this may seem like an overkill, it gets optimized by ghc. I don't have any experience with lenses, but they should be usable here. Understanding them will require a good understanding of the type system. On 13 March 2015 at 04:32, Timothy Washington wrote: > To get started, I'm trying to implement a simple *tictactoe* game. And I > would like to be able to represent a Piece on the board, as either the > string "X" or "O". This is what I have so far. > > module Main where > > data Piece = X | O > type Row = [Piece] > type Board = [Row] > > -- put an X or O in a position > move :: Board -> Piece -> Board > move board piece = board > > -- check win vertically > -- check win horizontally > -- check win diagonally > > main :: IO () > main = putStrLn "Hello World" > > > > *A)* Now, I'd like to be able to *load code interactively*, preferably > within emacs. However I don't have access to my types with *ghci* or *ghc-mod > (Interactive-Haskell)*. In either case, this call fails with the below > error. > > > let p = Piece X > :20:9-13: Not in scope: data constructor `Piece' > > > *B)* And how do I make a *custom datatype* that's one of two strings > (enumeration of either "X" or "O"). Cabal builds and runs the abouve code, > so I know it can compile. But I'm confused as to where X or O is defined, > and how I would supply it as an input. > > *C)* Finally, how do we update nested lists in Haskell. I want the move > function to take a Board, Piece, and Position, and return a Board. I see > some results from Hoogle . > Is this where Lenses or > Zippers come into play? > > > Thanks > > Tim Washington > Interruptsoftware.com > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -- Regards Sumit Sahrawat -------------- next part -------------- An HTML attachment was scrubbed... URL: From ky3 at atamo.com Thu Mar 12 23:53:55 2015 From: ky3 at atamo.com (Kim-Ee Yeoh) Date: Fri, 13 Mar 2015 06:53:55 +0700 Subject: [Haskell-beginners] Dipping Toes Into Haskell In-Reply-To: References: Message-ID: Hi Tim, Congrats on your choice of tic-tac-toe. I also believe it's a good toy to get your feet wet with haskell. 1. Your concerns about writing a "custom datatype" are best addressed by reading up on it. If you search for "haskell data type declarations", you'll find good material explaining the difference between "data", "newtype", and "type" declarations. You'll also understand the meaning of the error message and what "data constructor" refers to. 2. Functions defined on lists are here: https://hackage.haskell.org/package/base/docs/Data-List.html The update function you're looking for is (!!). -- Kim-Ee On Fri, Mar 13, 2015 at 6:02 AM, Timothy Washington wrote: > To get started, I'm trying to implement a simple *tictactoe* game. And I > would like to be able to represent a Piece on the board, as either the > string "X" or "O". This is what I have so far. > > module Main where > > data Piece = X | O > type Row = [Piece] > type Board = [Row] > > -- put an X or O in a position > move :: Board -> Piece -> Board > move board piece = board > > -- check win vertically > -- check win horizontally > -- check win diagonally > > main :: IO () > main = putStrLn "Hello World" > > > > *A)* Now, I'd like to be able to *load code interactively*, preferably > within emacs. However I don't have access to my types with *ghci* or *ghc-mod > (Interactive-Haskell)*. In either case, this call fails with the below > error. > > > let p = Piece X > :20:9-13: Not in scope: data constructor `Piece' > > > *B)* And how do I make a *custom datatype* that's one of two strings > (enumeration of either "X" or "O"). Cabal builds and runs the abouve code, > so I know it can compile. But I'm confused as to where X or O is defined, > and how I would supply it as an input. > > *C)* Finally, how do we update nested lists in Haskell. I want the move > function to take a Board, Piece, and Position, and return a Board. I see > some results from Hoogle . > Is this where Lenses or > Zippers come into play? > > > Thanks > > Tim Washington > Interruptsoftware.com > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mwm at mired.org Fri Mar 13 00:03:51 2015 From: mwm at mired.org (Mike Meyer) Date: Thu, 12 Mar 2015 19:03:51 -0500 Subject: [Haskell-beginners] Dipping Toes Into Haskell In-Reply-To: References: Message-ID: On Thu, Mar 12, 2015 at 6:02 PM, Timothy Washington wrote: > To get started, I'm trying to implement a simple *tictactoe* game. And I > would like to be able to represent a Piece on the board, as either the > string "X" or "O". This is what I have so far. > > module Main where > > data Piece = X | O > type Row = [Piece] > type Board = [Row] > > -- put an X or O in a position > move :: Board -> Piece -> Board > move board piece = board > > -- check win vertically > -- check win horizontally > -- check win diagonally > > main :: IO () > main = putStrLn "Hello World" > > > > *A)* Now, I'd like to be able to *load code interactively*, preferably > within emacs. However I don't have access to my types with *ghci* or *ghc-mod > (Interactive-Haskell)*. In either case, this call fails with the below > error. > > > let p = Piece X > :20:9-13: Not in scope: data constructor `Piece' > > Piece is the data TYPE. It has two constructors, X, and O. If you load your module into ghci, you can do ":t X" to get the type of X, which is Piece. You want to do "let p = X" here. Check your mode docs while editing the haskell file. There should be a command to load the current buffer into a ghci running in an interactive emacs buffer. > *B)* And how do I make a *custom datatype* that's one of two strings > (enumeration of either "X" or "O"). Cabal builds and runs the abouve code, > so I know it can compile. But I'm confused as to where X or O is defined, > and how I would supply it as an input. > As noted, you can derive "Show" so that Piece types print as "X" and "O". Similarly, you can derive "Read": data Piece = X | O deriving (Show, Read) so that you can then read "X" and get back an X when the context calls for a Piece value: *Main> read "X" :: Piece X However, this isn't used a lot, as it tends to be slow and not very flexible for more complex types. For instance, it will let you read in lists of Pieces and lists of lists, but you'l lhave to use the list syntax, not something that looks like an actual board when printed. -------------- next part -------------- An HTML attachment was scrubbed... URL: From twashing at gmail.com Fri Mar 13 00:14:30 2015 From: twashing at gmail.com (Timothy Washington) Date: Thu, 12 Mar 2015 20:14:30 -0400 Subject: [Haskell-beginners] Dipping Toes Into Haskell In-Reply-To: References: Message-ID: Good explanation. Thank-you. Tim Washington Interruptsoftware.com On Thu, Mar 12, 2015 at 7:50 PM, Sumit Sahrawat, Maths & Computing, IIT (BHU) wrote: > data Piece = X | O > > means that X and O are constants, having data type 'Piece'. > In other words, you directly use X and O instead of Piece X and Piece O. > > Piece is a type, and X and O are constructors (or simply the two possible > values). > > A good similar example is the Bool type, > > data Bool = False | True > -- Two possible values, i.e. False and True > > For more info, take a look here: > http://en.wikibooks.org/wiki/Haskell/Type_declarations > > Also, to make life easier, you might want to use: > > data Piece = X | O > deriving Show -- Make this type showable > > With this, you will be able to use 'print' with elements of this datatype. > > For a tutorial on setting up emacs, take a look here: > https://github.com/serras/emacs-haskell-tutorial/blob/master/tutorial.md > > For updating nested lists, you have to create a function that takes two > numbers (the positions) and iterates over the whole structure, just > updating the required position. > While this may seem like an overkill, it gets optimized by ghc. > > I don't have any experience with lenses, but they should be usable here. > Understanding them will require a good understanding of the type system. > > On 13 March 2015 at 04:32, Timothy Washington wrote: > >> To get started, I'm trying to implement a simple *tictactoe* game. And I >> would like to be able to represent a Piece on the board, as either the >> string "X" or "O". This is what I have so far. >> >> module Main where >> >> data Piece = X | O >> type Row = [Piece] >> type Board = [Row] >> >> -- put an X or O in a position >> move :: Board -> Piece -> Board >> move board piece = board >> >> -- check win vertically >> -- check win horizontally >> -- check win diagonally >> >> main :: IO () >> main = putStrLn "Hello World" >> >> >> >> *A)* Now, I'd like to be able to *load code interactively*, preferably >> within emacs. However I don't have access to my types with *ghci* or *ghc-mod >> (Interactive-Haskell)*. In either case, this call fails with the below >> error. >> >> >> let p = Piece X >> :20:9-13: Not in scope: data constructor `Piece' >> >> >> *B)* And how do I make a *custom datatype* that's one of two strings >> (enumeration of either "X" or "O"). Cabal builds and runs the abouve code, >> so I know it can compile. But I'm confused as to where X or O is defined, >> and how I would supply it as an input. >> >> *C)* Finally, how do we update nested lists in Haskell. I want the move >> function to take a Board, Piece, and Position, and return a Board. I see >> some results from Hoogle . >> Is this where Lenses or >> Zippers come into play? >> >> >> Thanks >> >> Tim Washington >> Interruptsoftware.com >> >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> > > > -- > Regards > > Sumit Sahrawat > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From twashing at gmail.com Fri Mar 13 00:15:14 2015 From: twashing at gmail.com (Timothy Washington) Date: Thu, 12 Mar 2015 20:15:14 -0400 Subject: [Haskell-beginners] Dipping Toes Into Haskell In-Reply-To: References: Message-ID: Thank-you :) And thanks for the Data.List docs. That's a good place to start. Tim Washington Interruptsoftware.com On Thu, Mar 12, 2015 at 7:53 PM, Kim-Ee Yeoh wrote: > Hi Tim, > > Congrats on your choice of tic-tac-toe. I also believe it's a good toy to > get your feet wet with haskell. > > 1. Your concerns about writing a "custom datatype" are best addressed by > reading up on it. If you search for "haskell data type declarations", > you'll find good material explaining the difference between "data", > "newtype", and "type" declarations. You'll also understand the meaning of > the error message and what "data constructor" refers to. > > 2. Functions defined on lists are here: > > https://hackage.haskell.org/package/base/docs/Data-List.html > > The update function you're looking for is (!!). > > > > > -- Kim-Ee > > On Fri, Mar 13, 2015 at 6:02 AM, Timothy Washington > wrote: > >> To get started, I'm trying to implement a simple *tictactoe* game. And I >> would like to be able to represent a Piece on the board, as either the >> string "X" or "O". This is what I have so far. >> >> module Main where >> >> data Piece = X | O >> type Row = [Piece] >> type Board = [Row] >> >> -- put an X or O in a position >> move :: Board -> Piece -> Board >> move board piece = board >> >> -- check win vertically >> -- check win horizontally >> -- check win diagonally >> >> main :: IO () >> main = putStrLn "Hello World" >> >> >> >> *A)* Now, I'd like to be able to *load code interactively*, preferably >> within emacs. However I don't have access to my types with *ghci* or *ghc-mod >> (Interactive-Haskell)*. In either case, this call fails with the below >> error. >> >> >> let p = Piece X >> :20:9-13: Not in scope: data constructor `Piece' >> >> >> *B)* And how do I make a *custom datatype* that's one of two strings >> (enumeration of either "X" or "O"). Cabal builds and runs the abouve code, >> so I know it can compile. But I'm confused as to where X or O is defined, >> and how I would supply it as an input. >> >> *C)* Finally, how do we update nested lists in Haskell. I want the move >> function to take a Board, Piece, and Position, and return a Board. I see >> some results from Hoogle . >> Is this where Lenses or >> Zippers come into play? >> >> >> Thanks >> >> Tim Washington >> Interruptsoftware.com >> >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From joel.neely at gmail.com Fri Mar 13 11:53:05 2015 From: joel.neely at gmail.com (Joel Neely) Date: Fri, 13 Mar 2015 06:53:05 -0500 Subject: [Haskell-beginners] Problems installing lambdabot Message-ID: I am using a recent install of Haskell platform (GHC/GHCi version 7.8.3) in OS X 10.9.5, and have been working through Real World Haskell and last year's CIS194 lectures and exercises. I attempted to follow the instructions for installing lambdabot (as given by https://wiki.haskell.org/Lambdabot ) via cabal install lambdabot. After 24 1/2 minutes, the process ended with a little over a dozen error messages apparently tracing to two occurrences of ExitFailure 1: MonadRandom-0.3.0.1 failed during the building phase. The exception was: ExitFailure 1 regex-pcre-0.94.4 failed during the building phase. The exception was: ExitFailure 1 ?The remaining messages were from components dependent on one or the other of those two. The logged failure for regex-pcre-0.94.4 ?included the following: Preprocessing library regex-pcre-0.94.4... Wrap.hsc:148:10: fatal error: 'pcre.h' file not found #include ^ 1 error generated. compiling dist/build/Text/Regex/PCRE/Wrap_hsc_make.c failed (exit code 1) ?and for MonadRandom-0.3.0.1 included: Preprocessing library MonadRandom-0.3.0.1... [1 of 2] Compiling Control.Monad.Random.Class ( Control/Monad/Random/Class.hs, dist/build/Control/Monad/Random/Class.o ) [2 of 2] Compiling Control.Monad.Random ( Control/Monad/Random.hs, dist/build/Control/Monad/Random.o ) [1 of 2] Compiling Control.Monad.Random.Class ( Control/Monad/Random/Class.hs, dist/build/Control/Monad/Random/Class.p_o ) [2 of 2] Compiling Control.Monad.Random ( Control/Monad/Random.hs, dist/build/Control/Monad/Random.p_o ) /Users/joel/.ghc/x86_64-darwin-7.8.3/package.conf.d/package.cache: openBinaryFile: does not exist (No such file or directory) ? ?I am at a loss for corrective actions. I would assume that I need to locate the pcre.h header file and put it in the "right place"?, but was unable to find the location of Wrap_hsc_make.c. And I don't know how to address the non-existence of openBinaryFile in package.cache. Thanks in advance for any advice on correcting the above problems! -jn- -- Beauty of style and harmony and grace and good rhythm depend on simplicity. - Plato -------------- next part -------------- An HTML attachment was scrubbed... URL: From allbery.b at gmail.com Fri Mar 13 12:01:38 2015 From: allbery.b at gmail.com (Brandon Allbery) Date: Fri, 13 Mar 2015 08:01:38 -0400 Subject: [Haskell-beginners] Problems installing lambdabot In-Reply-To: References: Message-ID: On Fri, Mar 13, 2015 at 7:53 AM, Joel Neely wrote: > The logged failure for regex-pcre-0.94.4 ?included the following: > > Preprocessing library regex-pcre-0.94.4... > Wrap.hsc:148:10: fatal error: 'pcre.h' file not found > #include > ^ > 1 error generated. > compiling dist/build/Text/Regex/PCRE/Wrap_hsc_make.c failed (exit code 1) > > Both of these are the same problem: cabal cannot operate your system package manager to install the developer headers / libraries for the system's pcre package (if it even has one; on a Mac you may need to get a pcre package from somewhere else). The other one looks like an internal problem with either ghc or cabal; I can't help offhand. -- brandon s allbery kf8nh sine nomine associates allbery.b at gmail.com ballbery at sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From sumit.sahrawat.apm13 at iitbhu.ac.in Sat Mar 14 18:11:45 2015 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Sat, 14 Mar 2015 23:41:45 +0530 Subject: [Haskell-beginners] [Haskell-cafe] Mathematical functions with multiple arguments In-Reply-To: References: Message-ID: Hi everybody, I have landed on a small problem. I have a list of length n, and a function ([Double] -> Double) that requires a list of length n. I want to use them with a my plotting function that takes a function (Vector n Double -> Double) and a (Vector n Double) where both n represent same length. I convert the known function to a new function newFunc = f . toList :: Vec pn Double -> Double -- Where pn is the peano encoding of n I then convert the list to a vector using fromList, but then I cannot pass them both to my plotting function. In other words, how can I convince the type system that the length of provided vector is the same as that required by the function. On 12 March 2015 at 14:12, Sumit Sahrawat, Maths & Computing, IIT (BHU) < sumit.sahrawat.apm13 at iitbhu.ac.in> wrote: > Yeah, Data.Vector.Fixed.toList worked. I had found it previously, but it > didn't work for Vec imported from Data.Fixed.Vector.Primitive (as (Double, > Double) doesn't have a Prim instance). > Then I had to switch to Data.Fixed.Vector.Unboxed, and it works now. > > Also, those shingles look interesting too. Thanks everybody. > > On 12 March 2015 at 12:35, Konstantine Rybnikov wrote: > >> Is `Data.Vector.Fixed.toList` is what you're looking for? >> >> On Thu, Mar 12, 2015 at 1:16 AM, Sumit Sahrawat, Maths & Computing, IIT >> (BHU) wrote: >> >>> The fixed-vector package uses a similar technique. The only trouble I'm >>> having is with converting Vec v (Double, Double) to [(Double, Double)] for >>> further use. I don't want to change all the code, but only the part where >>> the user provides me with arguments. >>> >>> I'll keep looking into it. Thanks for the help. >>> >>> On 12 March 2015 at 04:44, David Feuer wrote: >>> >>>> There are a lot of ways to do this sort of thing, and which one you >>>> choose will depend on exactly what you're trying to do. For example, you >>>> can write something vaguely like >>>> >>>> data Nat = Z | S Nat >>>> data SL (n :: Nat) a where >>>> Nil :: SL Z >>>> Cons :: a -> SL n a -> SL (S n) a >>>> >>>> plot :: forall (n::Nat) . (SL n Double -> Double) -> >>>> SL n (Double, Double) -> IO () >>>> On Mar 11, 2015 5:45 PM, "Sumit Sahrawat, Maths & Computing, IIT (BHU)" >>>> wrote: >>>> >>>>> Hi everybody, >>>>> >>>>> I have a function of type >>>>> >>>>> plot :: ([Double] -> Double) -- A function to plot >>>>> -> [(Double, Double)] -- Range for all arguments >>>>> -> IO () >>>>> >>>>> I want to enforce the fact that ranges for all arguments should be >>>>> provided. >>>>> Is there a way to make the type system enforce it? >>>>> >>>>> -- >>>>> Regards >>>>> >>>>> Sumit Sahrawat >>>>> >>>>> _______________________________________________ >>>>> Haskell-Cafe mailing list >>>>> Haskell-Cafe at haskell.org >>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe >>>>> >>>>> >>> >>> >>> -- >>> Regards >>> >>> Sumit Sahrawat >>> >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >>> >> > > > -- > Regards > > Sumit Sahrawat > -- Regards Sumit Sahrawat -------------- next part -------------- An HTML attachment was scrubbed... URL: From simon at vonos.net Sun Mar 15 16:17:17 2015 From: simon at vonos.net (Simon Kitching) Date: Sun, 15 Mar 2015 17:17:17 +0100 Subject: [Haskell-beginners] Equivalent of IO Monad in other functional languages? Message-ID: <5505B08D.3030305@vonos.net> [Note: learning haskell, not familiar with other functional languages] I have a question about handling impure operations in functional or semi-functional languages other than Haskell (eg OCaml, F#, Scala, ..). Haskell uses the IO monad to (a) cleanly separate pure and impure code, and (b) prevent function-calls from being reordered when they have side-effects that must happen in the right order. How do other languages handle this? AIUI, whether a Haskell function is 'pure' or not can be seen from its method signature : if it returns IO then it is impure. All standard library functions that have side-effects (read/write/etc) return IO, and any function that uses an IO value must return type IO. Do other functional languages (1) use a similar approach, or (2) not provide a way to be certain that a function is 'pure' (side-effect-free)? And AIUI the Haskell compiler/runtime can postpone evaluation of any function (laziness), or reorder function calls whever it thinks this good. However using the monad design pattern (deliberately) prevents this (each operation passes its value as a parameter to the subsequent operation, thus forcing an order of evaluation). Do other languages (a) not support compiler/runtime reordering of functions, or (b) have some other way of preventing functions with side-effects from being reordered? Thanks.. Simon From marcin.jan.mrotek at gmail.com Sun Mar 15 16:55:12 2015 From: marcin.jan.mrotek at gmail.com (Marcin Mrotek) Date: Sun, 15 Mar 2015 17:55:12 +0100 Subject: [Haskell-beginners] Equivalent of IO Monad in other functional languages? In-Reply-To: <5505B08D.3030305@vonos.net> References: <5505B08D.3030305@vonos.net> Message-ID: Hello, F* uses a somewhat similar approach: https://fstar-lang.org/tutorial/ (section 2, Types and Effects) Best regards, Marcin Mrotek From sumit.sahrawat.apm13 at iitbhu.ac.in Sun Mar 15 17:15:03 2015 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Sun, 15 Mar 2015 22:45:03 +0530 Subject: [Haskell-beginners] Equivalent of IO Monad in other functional languages? In-Reply-To: References: <5505B08D.3030305@vonos.net> Message-ID: Hello Simon, If you changed your perspective, you would realize that all functions in haskell are pure. A function is pure if it returns the same output if given the same input. Every monadic function (including functions returning IO) is also pure. For example, putStrLn :: String -> IO () -- A function that takes a string, and returns an impure computation -- which, when executed will print the given String. For any string, putStrLn applied to that same string always describes the same impure computation, thus the function is actually pure. I am not familiar with any other functional language, but there are not many purely functional ones out there [1]. I guess the impure ones get around this issue by giving in to impurity, but I'm not sure. I'll be interested in hearing more about the other languages too. [1] : http://en.wikipedia.org/wiki/List_of_programming_languages_by_type#Pure On 15 March 2015 at 22:25, Marcin Mrotek wrote: > Hello, > > F* uses a somewhat similar approach: https://fstar-lang.org/tutorial/ > (section 2, Types and Effects) > > Best regards, > Marcin Mrotek > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -- Regards Sumit Sahrawat -------------- next part -------------- An HTML attachment was scrubbed... URL: From amindfv at gmail.com Sun Mar 15 17:49:04 2015 From: amindfv at gmail.com (amindfv at gmail.com) Date: Sun, 15 Mar 2015 13:49:04 -0400 Subject: [Haskell-beginners] Equivalent of IO Monad in other functional languages? In-Reply-To: References: <5505B08D.3030305@vonos.net> Message-ID: From that perspective isn't every language pure? Haskell's still got "randomIO" and "print <=< readMVar" Tom El Mar 15, 2015, a las 13:15, "Sumit Sahrawat, Maths & Computing, IIT (BHU)" escribi?: > Hello Simon, > > If you changed your perspective, you would realize that all functions in haskell are pure. > A function is pure if it returns the same output if given the same input. Every monadic function (including functions returning IO) is also pure. > For example, > > putStrLn :: String -> IO () > -- A function that takes a string, and returns an impure computation > -- which, when executed will print the given String. > > For any string, putStrLn applied to that same string always describes the same impure computation, thus the function is actually pure. > I am not familiar with any other functional language, but there are not many purely functional ones out there [1]. > I guess the impure ones get around this issue by giving in to impurity, but I'm not sure. > > I'll be interested in hearing more about the other languages too. > > [1] : http://en.wikipedia.org/wiki/List_of_programming_languages_by_type#Pure > > On 15 March 2015 at 22:25, Marcin Mrotek wrote: >> Hello, >> >> F* uses a somewhat similar approach: https://fstar-lang.org/tutorial/ >> (section 2, Types and Effects) >> >> Best regards, >> Marcin Mrotek >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > > -- > Regards > > Sumit Sahrawat > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: From sumit.sahrawat.apm13 at iitbhu.ac.in Sun Mar 15 17:57:58 2015 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Sun, 15 Mar 2015 23:27:58 +0530 Subject: [Haskell-beginners] Equivalent of IO Monad in other functional languages? In-Reply-To: References: <5505B08D.3030305@vonos.net> Message-ID: Haskell is impure only when you use the unsafe* functions (atleast that's how I understand purity). My understanding is that a language is impure if it allows one to write arbitrary IO within a function and still give it a proper (mathematical) function type. In other words impurity arises only if you can unwrap the IO monad (which is what the unsafe functions do). The two examples you give above are pure under such a perspective, but I might be wrong. On 15 March 2015 at 23:19, wrote: > From that perspective isn't every language pure? Haskell's still got > "randomIO" and "print <=< readMVar" > > Tom > > > El Mar 15, 2015, a las 13:15, "Sumit Sahrawat, Maths & Computing, IIT > (BHU)" escribi?: > > Hello Simon, > > If you changed your perspective, you would realize that all functions in > haskell are pure. > A function is pure if it returns the same output if given the same input. > Every monadic function (including functions returning IO) is also pure. > For example, > > putStrLn :: String -> IO () > -- A function that takes a string, and returns an impure computation > -- which, when executed will print the given String. > > For any string, putStrLn applied to that same string always describes the > same impure computation, thus the function is actually pure. > I am not familiar with any other functional language, but there are not > many purely functional ones out there [1]. > I guess the impure ones get around this issue by giving in to impurity, > but I'm not sure. > > I'll be interested in hearing more about the other languages too. > > [1] : > http://en.wikipedia.org/wiki/List_of_programming_languages_by_type#Pure > > On 15 March 2015 at 22:25, Marcin Mrotek > wrote: > >> Hello, >> >> F* uses a somewhat similar approach: https://fstar-lang.org/tutorial/ >> (section 2, Types and Effects) >> >> Best regards, >> Marcin Mrotek >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > > > > -- > Regards > > Sumit Sahrawat > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -- Regards Sumit Sahrawat -------------- next part -------------- An HTML attachment was scrubbed... URL: From tonymorris at gmail.com Sun Mar 15 21:17:33 2015 From: tonymorris at gmail.com (Tony Morris) Date: Mon, 16 Mar 2015 07:17:33 +1000 Subject: [Haskell-beginners] Equivalent of IO Monad in other functional languages? In-Reply-To: <5505B08D.3030305@vonos.net> References: <5505B08D.3030305@vonos.net> Message-ID: <5505F6ED.5040806@gmail.com> Scalaz implements IO and ST as a library for Scala. http://eed3si9n.com/learning-scalaz/IO+Monad.html On 16/03/15 02:17, Simon Kitching wrote: > [Note: learning haskell, not familiar with other functional languages] > > I have a question about handling impure operations in functional or > semi-functional languages other than Haskell (eg OCaml, F#, Scala, ..). > > Haskell uses the IO monad to (a) cleanly separate pure and impure > code, and (b) prevent function-calls from being reordered when they > have side-effects that must happen in the right order. How do other > languages handle this? > > AIUI, whether a Haskell function is 'pure' or not can be seen from its > method signature : if it returns IO then it is impure. All standard > library functions that have side-effects (read/write/etc) return IO, > and any function that uses an IO value must return type IO. Do other > functional languages (1) use a similar approach, or (2) not provide a > way to be certain that a function is 'pure' (side-effect-free)? > > And AIUI the Haskell compiler/runtime can postpone evaluation of any > function (laziness), or reorder function calls whever it thinks this > good. However using the monad design pattern (deliberately) prevents > this (each operation passes its value as a parameter to the subsequent > operation, thus forcing an order of evaluation). Do other languages > (a) not support compiler/runtime reordering of functions, or (b) have > some other way of preventing functions with side-effects from being > reordered? > > Thanks.. > Simon > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From karl at karlv.net Sun Mar 15 21:44:02 2015 From: karl at karlv.net (Karl Voelker) Date: Sun, 15 Mar 2015 14:44:02 -0700 Subject: [Haskell-beginners] Equivalent of IO Monad in other functional languages? In-Reply-To: <5505B08D.3030305@vonos.net> References: <5505B08D.3030305@vonos.net> Message-ID: <1426455842.3291431.240699409.6E305DDB@webmail.messagingengine.com> On Sun, Mar 15, 2015, at 09:17 AM, Simon Kitching wrote: > And AIUI the Haskell compiler/runtime can postpone evaluation of any > function (laziness), or reorder function calls whever it thinks this > good. It's not that it "can" but that it must. Haskell's evaluation strategy is a part of the language specification. Consider this expression: let f = 1 : f in take 5 f You can paste this into ghci and feel confident that it's going to terminate. You're not at the whim of the runtime. I think you may find these articles interesting: https://wiki.haskell.org/Lazy_evaluation https://wiki.haskell.org/Non-strict_semantics -Karl From apfelmus at quantentunnel.de Mon Mar 16 14:04:08 2015 From: apfelmus at quantentunnel.de (Heinrich Apfelmus) Date: Mon, 16 Mar 2015 15:04:08 +0100 Subject: [Haskell-beginners] Equivalent of IO Monad in other functional languages? In-Reply-To: References: <5505B08D.3030305@vonos.net> Message-ID: Sumit Sahrawat, Maths & Computing, IIT (BHU) wrote: > On 15 March 2015 at 23:19, wrote: > >> From that perspective isn't every language pure? Haskell's still got >> "randomIO" and "print <=< readMVar" > > Haskell is impure only when you use the unsafe* functions (atleast that's > how I understand purity). > > My understanding is that a language is impure if it allows one to write > arbitrary IO within a function and still give it a proper (mathematical) > function type. In other words impurity arises only if you can unwrap the IO > monad (which is what the unsafe functions do). > > The two examples you give above are pure under such a perspective, but I > might be wrong. You're right, indeed. A language is pure if supplying a value `x` of type `A` to the a function A -> B will always returns the same result, no matter how often or in which order this function is called. This is true for both randomIO :: Random a => IO a (readMVar >=> print) :: Show a => MVar a -> IO () because they return an IO action. This action will always be the same given the same arguments. The language would be impure if these functions had the types randomIO :: Random a => a (readMVar >=> print) :: Show a => MVar a -> () Best regards, Heinrich Apfelmus -- http://apfelmus.nfshost.com From apfelmus at quantentunnel.de Mon Mar 16 14:11:15 2015 From: apfelmus at quantentunnel.de (Heinrich Apfelmus) Date: Mon, 16 Mar 2015 15:11:15 +0100 Subject: [Haskell-beginners] Equivalent of IO Monad in other functional languages? In-Reply-To: <1426455842.3291431.240699409.6E305DDB@webmail.messagingengine.com> References: <5505B08D.3030305@vonos.net> <1426455842.3291431.240699409.6E305DDB@webmail.messagingengine.com> Message-ID: Karl Voelker wrote: > On Sun, Mar 15, 2015, at 09:17 AM, Simon Kitching wrote: >> And AIUI the Haskell compiler/runtime can postpone evaluation of any >> function (laziness), or reorder function calls whever it thinks this >> good. > > It's not that it "can" but that it must. Haskell's evaluation strategy > is a part of the language specification. > > Consider this expression: > > let f = 1 : f in take 5 f > > You can paste this into ghci and feel confident that it's going to > terminate. You're not at the whim of the runtime. > > I think you may find these articles interesting: > > https://wiki.haskell.org/Lazy_evaluation > https://wiki.haskell.org/Non-strict_semantics Strictly speaking, the Haskell language standard only specifies that Haskell has non-strict semantics, not that it needs to be evaluated using lazy evaluation. Of course, the two are related. I have tried to expand on the details here: https://hackhands.com/non-strict-semantics-haskell Best regards, Heinrich Apfelmus -- http://apfelmus.nfshost.com From mrz.vtl at gmail.com Mon Mar 16 14:21:33 2015 From: mrz.vtl at gmail.com (Maurizio Vitale) Date: Mon, 16 Mar 2015 10:21:33 -0400 Subject: [Haskell-beginners] testing IO code Message-ID: suppose I have a restricted IO monad, RIO that only exposes readFile. and then I have a monad SIO that will eventually provide a virtual file system from a map path->content, also with a readFile function returning SIO(String). What is the way to write a function parseFile that can operate in both monads so that I can use SIO for testing? should I define a third monad CompileMonad that has instances for both RIO and SIO and then having parseFile :: CompileMonad ast? Thanks, Maurizio -------------- next part -------------- An HTML attachment was scrubbed... URL: From sumit.sahrawat.apm13 at iitbhu.ac.in Mon Mar 16 14:24:41 2015 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Mon, 16 Mar 2015 19:54:41 +0530 Subject: [Haskell-beginners] Equivalent of IO Monad in other functional languages? In-Reply-To: References: <5505B08D.3030305@vonos.net> <1426455842.3291431.240699409.6E305DDB@webmail.messagingengine.com> Message-ID: Hi Heinrich, Thanks for confirming my concepts. It took me a long time pondering over what it meant to be purely functional. Great articles btw (+1). On 16 March 2015 at 19:41, Heinrich Apfelmus wrote: > Karl Voelker wrote: > >> On Sun, Mar 15, 2015, at 09:17 AM, Simon Kitching wrote: >> >>> And AIUI the Haskell compiler/runtime can postpone evaluation of any >>> function (laziness), or reorder function calls whever it thinks this good. >>> >> >> It's not that it "can" but that it must. Haskell's evaluation strategy >> is a part of the language specification. >> >> Consider this expression: >> >> let f = 1 : f in take 5 f >> >> You can paste this into ghci and feel confident that it's going to >> terminate. You're not at the whim of the runtime. >> >> I think you may find these articles interesting: >> >> https://wiki.haskell.org/Lazy_evaluation >> https://wiki.haskell.org/Non-strict_semantics >> > > Strictly speaking, the Haskell language standard only specifies that > Haskell has non-strict semantics, not that it needs to be evaluated using > lazy evaluation. > > Of course, the two are related. I have tried to expand on the details here: > > https://hackhands.com/non-strict-semantics-haskell > > > Best regards, > Heinrich Apfelmus > > -- > http://apfelmus.nfshost.com > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -- Regards Sumit Sahrawat -------------- next part -------------- An HTML attachment was scrubbed... URL: From raabe at froglogic.com Mon Mar 16 14:34:41 2015 From: raabe at froglogic.com (Frerich Raabe) Date: Mon, 16 Mar 2015 15:34:41 +0100 Subject: [Haskell-beginners] =?utf-8?q?Equivalent_of_IO_Monad_in_other_fun?= =?utf-8?q?ctional_languages=3F?= In-Reply-To: References: <5505B08D.3030305@vonos.net> Message-ID: <791472dcf2df420d2c3dcc8ab1a9ecb0@roundcube.froglogic.com> Hi, I also used to share this "Every function in Haskell is pure, as long as it does not use any of the unsafe* functions" view but by now I'm wondering whether that's really a useful definition. It may be true that putStrLn :: String -> IO () is pure in the sense that it only yields a 'recipe' for printing the given string instead of actually printing it. However, I think it's important to realize that putStrLn *could* actually yield a poisoned recipe, something which not *only* prints a string but which also plays a sound at 4AM. And the types won't let you know whether this is the case. Hence, even though putStrLn may be pure in the classical 'same input yields same output' sense, I wondr whether it's more useful to consider putStrLn to be impure on the grounds that a value of type 'IO a' means "anything can happen, and whatever happens doesn't necessarily only depend on the arguments". On 2015-03-15 18:57, Sumit Sahrawat, Maths & Computing, IIT (BHU) wrote: > Haskell is impure only when you use the unsafe* functions (atleast that's > how I understand purity). > > My understanding is that a language is impure if it allows one to write > arbitrary IO within a function and still give it a proper > (mathematical) function type. In other words impurity arises only if you can > unwrap the IO monad (which is what the unsafe functions do). > > The two examples you give above are pure under such a perspective, but I > might be wrong. > > On 15 March 2015 at 23:19, wrote: > >> From that perspective isn't every language pure? Haskell's still got >> "randomIO" and "print <=< readMVar" >> >> Tom >> >> El Mar 15, 2015, a las 13:15, "Sumit Sahrawat, Maths & Computing, IIT >> (BHU)" escribi?: >> >> Hello Simon, >> >> If you changed your perspective, you would realize that all functions in >> haskell are pure. >> A function is pure if it returns the same output if given the same input. >> Every monadic function (including functions returning IO) is also >> pure. >> For example, >> >> putStrLn :: String -> IO () >> -- A function that takes a string, and returns an impure computation >> -- which, when executed will print the given String. >> >> For any string, putStrLn applied to that same string always describes the >> same impure computation, thus the function is actually pure. >> I am not familiar with any other functional language, but there are not >> many purely functional ones out there [1]. >> I guess the impure ones get around this issue by giving in to impurity, but >> I'm not sure. >> >> I'll be interested in hearing more about the other languages too. >> >> [1] : >> http://en.wikipedia.org/wiki/List_of_programming_languages_by_type#Pure [1] >> >> On 15 March 2015 at 22:25, Marcin Mrotek >> wrote: >> Hello, >> >> F* uses a somewhat similar approach: https://fstar-lang.org/tutorial/ [2] >> (section 2, Types and Effects) >> >> Best regards, >> Marcin Mrotek >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners [3] >> >> -- >> >> Regards >> >> Sumit Sahrawat > >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners [3] > > -- > > Regards > > Sumit Sahrawat > > Links: > ------ > [1] http://en.wikipedia.org/wiki/List_of_programming_languages_by_type#Pure > [2] https://fstar-lang.org/tutorial/ > [3] http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -- Frerich Raabe - raabe at froglogic.com www.froglogic.com - Multi-Platform GUI Testing From simon at vonos.net Mon Mar 16 14:35:33 2015 From: simon at vonos.net (Simon Kitching) Date: Mon, 16 Mar 2015 15:35:33 +0100 Subject: [Haskell-beginners] Equivalent of IO Monad in other functional languages? In-Reply-To: References: <5505B08D.3030305@vonos.net> Message-ID: <5506EA35.8080303@vonos.net> On 03/16/2015 03:04 PM, Heinrich Apfelmus wrote: > Sumit Sahrawat, Maths & Computing, IIT (BHU) wrote: >> On 15 March 2015 at 23:19, wrote: >> >>> From that perspective isn't every language pure? Haskell's still got >>> "randomIO" and "print <=< readMVar" >> >> Haskell is impure only when you use the unsafe* functions (atleast >> that's >> how I understand purity). >> >> My understanding is that a language is impure if it allows one to write >> arbitrary IO within a function and still give it a proper (mathematical) >> function type. In other words impurity arises only if you can unwrap >> the IO >> monad (which is what the unsafe functions do). >> >> The two examples you give above are pure under such a perspective, but I >> might be wrong. > > You're right, indeed. A language is pure if supplying a value `x` of > type `A` to the a function > > A -> B > > will always returns the same result, no matter how often or in which > order this function is called. This is true for both > > randomIO :: Random a => IO a > (readMVar >=> print) :: Show a => MVar a -> IO () > > because they return an IO action. This action will always be the same > given the same arguments. > > The language would be impure if these functions had the types > > randomIO :: Random a => a > (readMVar >=> print) :: Show a => MVar a -> () Maybe I should have phrased my original question differently. Let me try again.. In an imperative language, you can write something like the following pseudocode: String transform(String name) { print "enter greeting:" greeting = read-line-from-stdin return greeting + " " + name } From the "outside", there is no way to tell whether the function "transform" performs IO, mutates global state, mutates its parameter, or anything else. And this is just _normal_ for imperative-programming; if you want to write a unit-test for a method, you need to somehow _know_ what external state it might depend on/affect. And compilers cannot reorder or omit functions because any function might have side-effects. In Haskell, the function signature clearly indicates if this kind of thing is happening - any function like the above will have a return type of IO, thus clearly separating code with side-effects from code without side-effects. I was wondering what other functional or partly-functional languages (OCaml, F#, Scheme etc) do - do they also give the user of a function a way to tell whether the function has IO side-effects (reading/writing) or does the user just need to "consult the documentation" or "read the source code"? Thanks, Simon From simon at vonos.net Mon Mar 16 14:45:20 2015 From: simon at vonos.net (Simon Kitching) Date: Mon, 16 Mar 2015 15:45:20 +0100 Subject: [Haskell-beginners] Equivalent of IO Monad in other functional languages? In-Reply-To: References: <5505B08D.3030305@vonos.net> Message-ID: <5506EC80.4080602@vonos.net> On 03/16/2015 03:04 PM, Heinrich Apfelmus wrote: > Sumit Sahrawat, Maths & Computing, IIT (BHU) wrote: >> On 15 March 2015 at 23:19, wrote: >> >>> From that perspective isn't every language pure? Haskell's still got >>> "randomIO" and "print <=< readMVar" >> >> Haskell is impure only when you use the unsafe* functions (atleast >> that's >> how I understand purity). >> >> My understanding is that a language is impure if it allows one to write >> arbitrary IO within a function and still give it a proper (mathematical) >> function type. In other words impurity arises only if you can unwrap >> the IO >> monad (which is what the unsafe functions do). >> >> The two examples you give above are pure under such a perspective, but I >> might be wrong. > > You're right, indeed. A language is pure if supplying a value `x` of > type `A` to the a function > > A -> B > > will always returns the same result, no matter how often or in which > order this function is called. This is true for both > > randomIO :: Random a => IO a > (readMVar >=> print) :: Show a => MVar a -> IO () > > because they return an IO action. This action will always be the same > given the same arguments. > > The language would be impure if these functions had the types > > randomIO :: Random a => a > (readMVar >=> print) :: Show a => MVar a -> () Doesn't "pure" correspond to "can write a unit test for"? When a function's return value only ever depends on its inputs, then I can write a set of test-cases for various inputs, and assert that the return-value has the expected content. A function that reads from a file, stdin, etc. cannot be tested in the same way; I cannot _assert_ that the returned value has specific content. Sumit stated earlier that IO is "a pure program that can be executed", which seems similar to your description above (which I admit I don't yet 100% understand). How can I "assert" anything about this "program", or make a Haskell-based application 'safer' in any way by leveraging this kind of 'purity'? Thanks, Simon From sumit.sahrawat.apm13 at iitbhu.ac.in Mon Mar 16 14:40:35 2015 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Mon, 16 Mar 2015 20:10:35 +0530 Subject: [Haskell-beginners] testing IO code In-Reply-To: References: Message-ID: On 16 March 2015 at 19:51, Maurizio Vitale wrote: > suppose I have a restricted IO monad, RIO that only exposes readFile. > and then I have a monad SIO that will eventually provide a virtual file > system from a map path->content, also with a readFile function returning > SIO(String). > > What is the way to write a function parseFile that can operate in both > monads so that I can use SIO for testing? should I define a third monad > CompileMonad that has instances for both RIO and SIO and then having > parseFile :: CompileMonad ast? > You might be able to do something like, class MonadIO m => ProvidesReadFile m where readFile :: FilePath -> m String instance ProvidesReadFile RIO where readFile = readFileRIO -- the RIO specific readFile instance ProvidesReadFile SIO where readFile = readFileSIO -- the SIO specific readFile parseFile :: ProvidesReadFile m => FilePath -> m ast parseFile = do f <- readFile let ast = parse f -- the pure parser return ast -- works for both monads > Thanks, > > Maurizio > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > This is more suitable for the haskell-cafe. I am posting it there so that more people might comment on it. HTH. -- Regards Sumit Sahrawat -------------- next part -------------- An HTML attachment was scrubbed... URL: From sumit.sahrawat.apm13 at iitbhu.ac.in Mon Mar 16 14:58:27 2015 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Mon, 16 Mar 2015 20:28:27 +0530 Subject: [Haskell-beginners] Equivalent of IO Monad in other functional languages? In-Reply-To: <5506EC80.4080602@vonos.net> References: <5505B08D.3030305@vonos.net> <5506EC80.4080602@vonos.net> Message-ID: Sorry for having strayed towards a different path. I'll try to answer only your question this time :) An example from [1], for SML (bottom of the page) shows a function, with the following type signature in haskell copyTextFile :: String -> String One cannot write such a function in haskell that does the same thing because the example uses IO within a function with a pure looking type. I'm sure people experienced with other functional languages will have good examples, so I'll leave it to them. To answer your second question, I'm still not sure :). I was just relaying how I understood purity, so that somebody might also correct me if I'm wrong. Summarizing the discussion above, a function is pure if it gives the same output for the same input. Now a function returning 'IO a' always returns the same IO instructions (these instructions might be impure), but the function (by the virtue of always returning the same output for the same inputs) is ultimately pure. Frerich has also raised an important point that an IO computation might actually depend on some random file, which breaks this pattern. [1]: http://www.cs.cornell.edu/courses/cs312/2006fa/recitations/rec09.html On 16 March 2015 at 20:15, Simon Kitching wrote: > On 03/16/2015 03:04 PM, Heinrich Apfelmus wrote: > >> Sumit Sahrawat, Maths & Computing, IIT (BHU) wrote: >> >>> On 15 March 2015 at 23:19, wrote: >>> >>> From that perspective isn't every language pure? Haskell's still got >>>> "randomIO" and "print <=< readMVar" >>>> >>> >>> Haskell is impure only when you use the unsafe* functions (atleast that's >>> how I understand purity). >>> >>> My understanding is that a language is impure if it allows one to write >>> arbitrary IO within a function and still give it a proper (mathematical) >>> function type. In other words impurity arises only if you can unwrap the >>> IO >>> monad (which is what the unsafe functions do). >>> >>> The two examples you give above are pure under such a perspective, but I >>> might be wrong. >>> >> >> You're right, indeed. A language is pure if supplying a value `x` of type >> `A` to the a function >> >> A -> B >> >> will always returns the same result, no matter how often or in which >> order this function is called. This is true for both >> >> randomIO :: Random a => IO a >> (readMVar >=> print) :: Show a => MVar a -> IO () >> >> because they return an IO action. This action will always be the same >> given the same arguments. >> >> The language would be impure if these functions had the types >> >> randomIO :: Random a => a >> (readMVar >=> print) :: Show a => MVar a -> () >> > > Doesn't "pure" correspond to "can write a unit test for"? When a > function's return value only ever depends on its inputs, then I can > write a set of test-cases for various inputs, and assert that the > return-value has the expected content. > > A function that reads from a file, stdin, etc. cannot be tested in the > same way; I cannot _assert_ that the returned value has specific content. > > Sumit stated earlier that IO is "a pure program that can be executed", > which seems similar to your description above (which I admit I > don't yet 100% understand). How can I "assert" anything about this > "program", or make a Haskell-based application 'safer' in any way by > leveraging this kind of 'purity'? > > Thanks, > Simon > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -- Regards Sumit Sahrawat -------------- next part -------------- An HTML attachment was scrubbed... URL: From sumit.sahrawat.apm13 at iitbhu.ac.in Mon Mar 16 15:01:06 2015 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Mon, 16 Mar 2015 20:31:06 +0530 Subject: [Haskell-beginners] Equivalent of IO Monad in other functional languages? In-Reply-To: References: <5505B08D.3030305@vonos.net> <5506EC80.4080602@vonos.net> Message-ID: Frerich, the function would still be pure, even if it returns a poisoned recipe as you say. Thus, a little thought leads me to believe that the pattern would still not break if no unsafe* functions are used. On 16 March 2015 at 20:28, Sumit Sahrawat, Maths & Computing, IIT (BHU) < sumit.sahrawat.apm13 at iitbhu.ac.in> wrote: > Sorry for having strayed towards a different path. I'll try to answer only > your question this time :) > > An example from [1], for SML (bottom of the page) shows a function, with > the following type signature in haskell > > copyTextFile :: String -> String > > One cannot write such a function in haskell that does the same thing > because the example uses IO within a function with a pure looking type. > > I'm sure people experienced with other functional languages will have good > examples, so I'll leave it to them. > > To answer your second question, I'm still not sure :). > I was just relaying how I understood purity, so that somebody might also > correct me if I'm wrong. > > Summarizing the discussion above, a function is pure if it gives the same > output for the same input. Now a function returning 'IO a' always returns > the same IO instructions (these instructions might be impure), but the > function (by the virtue of always returning the same output for the same > inputs) is ultimately pure. Frerich has also raised an important point that > an IO computation might actually depend on some random file, which breaks > this pattern. > > [1]: http://www.cs.cornell.edu/courses/cs312/2006fa/recitations/rec09.html > > On 16 March 2015 at 20:15, Simon Kitching wrote: > >> On 03/16/2015 03:04 PM, Heinrich Apfelmus wrote: >> >>> Sumit Sahrawat, Maths & Computing, IIT (BHU) wrote: >>> >>>> On 15 March 2015 at 23:19, wrote: >>>> >>>> From that perspective isn't every language pure? Haskell's still got >>>>> "randomIO" and "print <=< readMVar" >>>>> >>>> >>>> Haskell is impure only when you use the unsafe* functions (atleast >>>> that's >>>> how I understand purity). >>>> >>>> My understanding is that a language is impure if it allows one to write >>>> arbitrary IO within a function and still give it a proper (mathematical) >>>> function type. In other words impurity arises only if you can unwrap >>>> the IO >>>> monad (which is what the unsafe functions do). >>>> >>>> The two examples you give above are pure under such a perspective, but I >>>> might be wrong. >>>> >>> >>> You're right, indeed. A language is pure if supplying a value `x` of >>> type `A` to the a function >>> >>> A -> B >>> >>> will always returns the same result, no matter how often or in which >>> order this function is called. This is true for both >>> >>> randomIO :: Random a => IO a >>> (readMVar >=> print) :: Show a => MVar a -> IO () >>> >>> because they return an IO action. This action will always be the same >>> given the same arguments. >>> >>> The language would be impure if these functions had the types >>> >>> randomIO :: Random a => a >>> (readMVar >=> print) :: Show a => MVar a -> () >>> >> >> Doesn't "pure" correspond to "can write a unit test for"? When a >> function's return value only ever depends on its inputs, then I can >> write a set of test-cases for various inputs, and assert that the >> return-value has the expected content. >> >> A function that reads from a file, stdin, etc. cannot be tested in the >> same way; I cannot _assert_ that the returned value has specific content. >> >> Sumit stated earlier that IO is "a pure program that can be executed", >> which seems similar to your description above (which I admit I >> don't yet 100% understand). How can I "assert" anything about this >> "program", or make a Haskell-based application 'safer' in any way by >> leveraging this kind of 'purity'? >> >> Thanks, >> Simon >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> > > > > -- > Regards > > Sumit Sahrawat > -- Regards Sumit Sahrawat -------------- next part -------------- An HTML attachment was scrubbed... URL: From mrz.vtl at gmail.com Mon Mar 16 16:06:01 2015 From: mrz.vtl at gmail.com (Maurizio Vitale) Date: Mon, 16 Mar 2015 09:06:01 -0700 Subject: [Haskell-beginners] testing IO code In-Reply-To: References: Message-ID: Thanks! This is what I had in mind, except that I'm new too Haskell so I tried English instead of code for expressing it :-) I'll also check the IOSpec package Paul suggested, On Mon, Mar 16, 2015 at 7:40 AM, Sumit Sahrawat, Maths & Computing, IIT (BHU) wrote: > On 16 March 2015 at 19:51, Maurizio Vitale wrote: > >> suppose I have a restricted IO monad, RIO that only exposes readFile. >> and then I have a monad SIO that will eventually provide a virtual file >> system from a map path->content, also with a readFile function returning >> SIO(String). >> >> What is the way to write a function parseFile that can operate in both >> monads so that I can use SIO for testing? should I define a third monad >> CompileMonad that has instances for both RIO and SIO and then having >> parseFile :: CompileMonad ast? >> > > You might be able to do something like, > > class MonadIO m => ProvidesReadFile m where > readFile :: FilePath -> m String > > instance ProvidesReadFile RIO where > readFile = readFileRIO -- the RIO specific readFile > > instance ProvidesReadFile SIO where > readFile = readFileSIO -- the SIO specific readFile > > parseFile :: ProvidesReadFile m => FilePath -> m ast > parseFile = do > f <- readFile > let ast = parse f -- the pure parser > return ast -- works for both monads > > >> Thanks, >> >> Maurizio >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> > This is more suitable for the haskell-cafe. I am posting it there so that > more people might comment on it. > HTH. > > -- > Regards > > Sumit Sahrawat > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kc1956 at gmail.com Mon Mar 16 20:53:13 2015 From: kc1956 at gmail.com (KC) Date: Mon, 16 Mar 2015 13:53:13 -0700 Subject: [Haskell-beginners] There has been discussion on matrix operations and cache thrashing; does management think using Haskell would lead to cash thrashing? Message-ID: There has been discussion on matrix operations and cache thrashing; does management think using Haskell would lead to cash thrashing? What could change management's mind? -- -- Sent from an expensive device which will be obsolete in a few months! :D Casey -------------- next part -------------- An HTML attachment was scrubbed... URL: From hjgtuyl at chello.nl Mon Mar 16 22:55:56 2015 From: hjgtuyl at chello.nl (Henk-Jan van Tuyl) Date: Mon, 16 Mar 2015 23:55:56 +0100 Subject: [Haskell-beginners] Saving intermediate calculations In-Reply-To: <110089426.4891942.1426174459028.JavaMail.yahoo@mail.yahoo.com> References: <110089426.4891942.1426174459028.JavaMail.yahoo@mail.yahoo.com> Message-ID: On Thu, 12 Mar 2015 16:34:19 +0100, Abhinav Kalawatia wrote: > Hi Henk, > I hope you are well :) > Thanks for your help with the solution for saving the intermediate > calculations. Henk, could you please help me understand the following > code snippet? > ewma1 a (x:xs) = reverse $ foldl' f [x] xs > where f m@(x':xs') n = ((a * n) + ((1 - a) * x')):m You can do mathematical substitution: ewma1 a (x:xs) = reverse $ foldl' f [x] xs where f m@(x':xs') n = ((a * n) + ((1 - a) * x')):m + (definition of foldl, which performs the same calculation as foldl', though not strict) foldl f z [] = z foldl f z (x:xs) = foldl f (f z x) xs => (substitute definition of foldl in ewma1) ewma1 a (x1:x2:xs) = reverse $ foldl' f (f [x1] x2) xs where f m@(x':xs') n = ((a * n) + ((1 - a) * x')):m => (substitute f) ewma1 a (x1:x2:xs) = reverse $ foldl' f (((a * x2) + ((1 - a) * x1)):[x1]) xs where f m@(x':xs') n = ((a * n) + ((1 - a) * x')):m Repeat the last two steps until the list is processed. There is a tool to display this automatically: Hat, but I could not get it to run properly on my Windows PC. The homepage is at: http://projects.haskell.org/hat/ Regards, Henk-Jan -- Folding at home What if you could share your unused computer power to help find a cure? In just 5 minutes you can join the world's biggest networked computer and get us closer sooner. Watch the video. http://folding.stanford.edu/ From apfelmus at quantentunnel.de Tue Mar 17 09:29:53 2015 From: apfelmus at quantentunnel.de (Heinrich Apfelmus) Date: Tue, 17 Mar 2015 10:29:53 +0100 Subject: [Haskell-beginners] Equivalent of IO Monad in other functional languages? In-Reply-To: <791472dcf2df420d2c3dcc8ab1a9ecb0@roundcube.froglogic.com> References: <5505B08D.3030305@vonos.net> <791472dcf2df420d2c3dcc8ab1a9ecb0@roundcube.froglogic.com> Message-ID: Frerich Raabe wrote: > > I also used to share this "Every function in Haskell is pure, as long as > it does not use any of the unsafe* functions" view but by now I'm > wondering whether that's really a useful definition. It may be true that > > putStrLn :: String -> IO () > > is pure in the sense that it only yields a 'recipe' for printing the > given string instead of actually printing it. However, I think it's > important to realize that putStrLn *could* actually yield a poisoned > recipe, something which not *only* prints a string but which also plays > a sound at 4AM. And the types won't let you know whether this is the case. > > Hence, even though putStrLn may be pure in the classical 'same input > yields same output' sense, I wondr whether it's more useful to consider > putStrLn to be impure on the grounds that a value of type 'IO a' means > "anything can happen, and whatever happens doesn't necessarily only > depend on the arguments". Well, purity of functions is still a useful concept, because it provides a useful invariant in the types. For instance, the well-known function map :: (a -> b) -> [a] -> [b] may assume that the first argument always returns equal results given equal arguments and hence can be applied in any order and as often as desired. On the other hand, mapM :: (a -> IO b) -> [a] -> IO [b] may not assume that and must be careful about the sequence of operations. Of course, an action IO a means that "anything can happen", but I don't think it's useful to call that "impure". It's a good thing that the nastiness of the `IO` type constructor is separated cleanly from the properties of the function arrow `->`. That leaves the question of how to reason about `IO` programs. This is explored in detail in Simon Peyton-Jones' tutorial "Tackling the awkward squad: monadic input/output, concurrency, exceptions, and foreign-language calls in Haskell" http://research.microsoft.com/en-us/um/people/simonpj/papers/marktoberdorf/ You may also like "The Operational Monad Tutorial", which doesn't cover IO, but tries to explain how other monads can be understood and implemented in terms of operational semantics: http://apfelmus.nfshost.com/articles/operational-monad.html Best regards, Heinrich Apfelmus -- http://apfelmus.nfshost.com From objitsu at gmail.com Tue Mar 17 11:52:46 2015 From: objitsu at gmail.com (emacstheviking) Date: Tue, 17 Mar 2015 11:52:46 +0000 Subject: [Haskell-beginners] There has been discussion on matrix operations and cache thrashing; does management think using Haskell would lead to cash thrashing? In-Reply-To: References: Message-ID: If "consultancy" was involved then cash thrashing is always an issue ;) On 16 March 2015 at 20:53, KC wrote: > There has been discussion on matrix operations and cache thrashing; does > management think using Haskell would lead to cash thrashing? > > What could change management's mind? > > -- > -- > > Sent from an expensive device which will be obsolete in a few months! :D > > Casey > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kelongcong at gmail.com Tue Mar 17 17:26:39 2015 From: kelongcong at gmail.com (Kelong Cong) Date: Tue, 17 Mar 2015 17:26:39 +0000 Subject: [Haskell-beginners] Is it possible to check list length at compile time? Message-ID: Hello, I have a function that takes a list as its parameter. The list must always have the same length, for example 16. Instead of producing a "Nothing" or bottom out when an invalid list is supplied, are there ways to verify this at compile time? If not, are there alternative data types that has this kind of functionality? Thanks, Kelong -------------- next part -------------- An HTML attachment was scrubbed... URL: From toad3k at gmail.com Tue Mar 17 17:53:35 2015 From: toad3k at gmail.com (David McBride) Date: Tue, 17 Mar 2015 13:53:35 -0400 Subject: [Haskell-beginners] Is it possible to check list length at compile time? In-Reply-To: References: Message-ID: It is possible to go part of the way. See for example, the NonEmpty type in the semigroups package. It is a list that always has at least one element by restricting the operations you can do to the type without turning it into a normal list. You could easily adapt that solution to a sixteen element list, but it might not be a reasonable amount of trouble to go through. On Tue, Mar 17, 2015 at 1:26 PM, Kelong Cong wrote: > Hello, > > I have a function that takes a list as its parameter. The list must always > have the same length, for example 16. Instead of producing a "Nothing" or > bottom out when an invalid list is supplied, are there ways to verify this > at compile time? If not, are there alternative data types that has this > kind of functionality? > > Thanks, > Kelong > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From fa-ml at ariis.it Tue Mar 17 18:05:04 2015 From: fa-ml at ariis.it (Francesco Ariis) Date: Tue, 17 Mar 2015 19:05:04 +0100 Subject: [Haskell-beginners] Is it possible to check list length at compile time? In-Reply-To: References: Message-ID: <20150317180504.GA6830@x60s.casa> On Tue, Mar 17, 2015 at 05:26:39PM +0000, Kelong Cong wrote: > I have a function that takes a list as its parameter. The list must always > have the same length, for example 16. Instead of producing a "Nothing" or > bottom out when an invalid list is supplied, are there ways to verify this > at compile time? If not, are there alternative data types that has this > kind of functionality? Wouldn't a gigantic 16-sized tuple solve the matter (or any datatype with 16 accessors)? What functions are you using on the list? From k-bx at k-bx.com Tue Mar 17 18:35:58 2015 From: k-bx at k-bx.com (Konstantine Rybnikov) Date: Tue, 17 Mar 2015 20:35:58 +0200 Subject: [Haskell-beginners] Is it possible to check list length at compile time? In-Reply-To: References: Message-ID: Hi Kelong! Check out https://hackage.haskell.org/package/sized-vector-0.0.2.0/docs/Data-Vector-Sized.html for a vector which has its size stored in type itself. Cheers. On Tue, Mar 17, 2015 at 7:26 PM, Kelong Cong wrote: > Hello, > > I have a function that takes a list as its parameter. The list must always > have the same length, for example 16. Instead of producing a "Nothing" or > bottom out when an invalid list is supplied, are there ways to verify this > at compile time? If not, are there alternative data types that has this > kind of functionality? > > Thanks, > Kelong > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From alt.mcarter at gmail.com Tue Mar 17 21:55:29 2015 From: alt.mcarter at gmail.com (Mark Carter) Date: Tue, 17 Mar 2015 21:55:29 +0000 Subject: [Haskell-beginners] Have I just broken Haskell? Message-ID: <5508A2D1.1090604@gmail.com> Persuant to my previous question, I have made some progress, but there is something odd going on. Suppose we want to implement the following algorithm, which is a little simpler than the original problem: The user types the name of a file as input. Haskell then puts the text "it works" to that file. I tried this: import System.IO let openFileWrite name = openFile name WriteMode h :: IO Handle h <- fmap openFileWrite getLine -- you need to type in a file name This looks wrong, because h presumably needs to be a fixed Handle. Being an IO Handle seems to imply it is mutable. Haskell doesn't complain, though. We also have the problem of how we are going to use hPutStr to put a string to the file. We can't do hPutStr h "it works" because h doesn't have the right type. I tried getting around it by creating a function let put s h = hPutStr h s fmap (put "it works") h But that doesn't work, it says *** Exception: wow: openFile: resource busy (file is locked) I'm guessing what I've done is create a stream OUT OF the file handle, rather than FOR THE file handle. Urgh! Any ideas what the fix is? From bob at redivi.com Tue Mar 17 22:16:25 2015 From: bob at redivi.com (Bob Ippolito) Date: Tue, 17 Mar 2015 15:16:25 -0700 Subject: [Haskell-beginners] Have I just broken Haskell? In-Reply-To: <5508A2D1.1090604@gmail.com> References: <5508A2D1.1090604@gmail.com> Message-ID: On Tue, Mar 17, 2015 at 2:55 PM, Mark Carter wrote: > Persuant to my previous question, I have made some progress, but there is > something odd going on. > > Suppose we want to implement the following algorithm, which is a little > simpler than the original problem: > > The user types the name of a file as input. Haskell then puts the text "it > works" to that file. I tried this: > > import System.IO > let openFileWrite name = openFile name WriteMode > h :: IO Handle > h <- fmap openFileWrite getLine -- you need to type in a file name > > This looks wrong, because h presumably needs to be a fixed Handle. Being > an IO Handle seems to imply it is mutable. Haskell doesn't complain, though. > This is wrong because the type of `h` should be Handle, not IO Handle. `fmap` is not the correct function to use here, you use `fmap` to lift a pure function into some Functor. What you need to do is sequence these two IO actions, like this: name <- getLine h <- openFileWrite name Which is equivalent to this: h <- getLine >>= openFileWrite or this (`=<<` is just a flipped `>>=` operator): h <- openFileWrite =<< getLine -bob -------------- next part -------------- An HTML attachment was scrubbed... URL: From kelongcong at gmail.com Tue Mar 17 22:50:19 2015 From: kelongcong at gmail.com (Kelong Cong) Date: Tue, 17 Mar 2015 22:50:19 +0000 Subject: [Haskell-beginners] Is it possible to check list length at compile time? In-Reply-To: References: Message-ID: Thanks for the suggestion guys, I think the sized vector is just what I needed! I know about tuples but I can't use the usual list functions like map, splitAt etc, also there is no need to have more than one data type. On 17 March 2015 at 18:35, Konstantine Rybnikov wrote: > Hi Kelong! > > Check out > https://hackage.haskell.org/package/sized-vector-0.0.2.0/docs/Data-Vector-Sized.html > for a vector which has its size stored in type itself. > > Cheers. > > On Tue, Mar 17, 2015 at 7:26 PM, Kelong Cong wrote: > >> Hello, >> >> I have a function that takes a list as its parameter. The list must >> always have the same length, for example 16. Instead of producing a >> "Nothing" or bottom out when an invalid list is supplied, are there ways to >> verify this at compile time? If not, are there alternative data types that >> has this kind of functionality? >> >> Thanks, >> Kelong >> >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From marcin.jan.mrotek at gmail.com Tue Mar 17 23:00:48 2015 From: marcin.jan.mrotek at gmail.com (Marcin Mrotek) Date: Wed, 18 Mar 2015 00:00:48 +0100 Subject: [Haskell-beginners] Is it possible to check list length at compile time? In-Reply-To: References: Message-ID: I think you're looking for dependend types or refinement types. It's sort of possible in Haskell, but look into Agda, Idris, F#, and this thread: http://www.reddit.com/r/haskell/comments/2z5l9y/question_type_system_and_ndimensional_vectors/ Best regards, Marcin Mrotek From anuragohri92 at gmail.com Wed Mar 18 01:51:26 2015 From: anuragohri92 at gmail.com (Anurag Ohri) Date: Wed, 18 Mar 2015 07:21:26 +0530 Subject: [Haskell-beginners] Have I just broken Haskell? In-Reply-To: References: <5508A2D1.1090604@gmail.com> Message-ID: I recently encountered the same Exception. It occurs when you open a file but don't close it using "hClose". On Mar 18, 2015 3:46 AM, "Bob Ippolito" wrote: > On Tue, Mar 17, 2015 at 2:55 PM, Mark Carter > wrote: > >> Persuant to my previous question, I have made some progress, but there is >> something odd going on. >> >> Suppose we want to implement the following algorithm, which is a little >> simpler than the original problem: >> >> The user types the name of a file as input. Haskell then puts the text >> "it works" to that file. I tried this: >> >> import System.IO >> let openFileWrite name = openFile name WriteMode >> h :: IO Handle >> h <- fmap openFileWrite getLine -- you need to type in a file name >> >> This looks wrong, because h presumably needs to be a fixed Handle. Being >> an IO Handle seems to imply it is mutable. Haskell doesn't complain, though. >> > > This is wrong because the type of `h` should be Handle, not IO Handle. > `fmap` is not the correct function to use here, you use `fmap` to lift a > pure function into some Functor. What you need to do is sequence these two > IO actions, like this: > > name <- getLine > h <- openFileWrite name > > Which is equivalent to this: > > h <- getLine >>= openFileWrite > > or this (`=<<` is just a flipped `>>=` operator): > > h <- openFileWrite =<< getLine > > -bob > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From chaddai.fouche at gmail.com Wed Mar 18 06:20:39 2015 From: chaddai.fouche at gmail.com (=?UTF-8?B?Q2hhZGRhw68gRm91Y2jDqQ==?=) Date: Wed, 18 Mar 2015 07:20:39 +0100 Subject: [Haskell-beginners] Have I just broken Haskell? In-Reply-To: <5508A2D1.1090604@gmail.com> References: <5508A2D1.1090604@gmail.com> Message-ID: On Tue, Mar 17, 2015 at 10:55 PM, Mark Carter wrote: > Persuant to my previous question, I have made some progress, but there is > something odd going on. > > Suppose we want to implement the following algorithm, which is a little > simpler than the original problem: > > The user types the name of a file as input. Haskell then puts the text "it > works" to that file. I tried this: > > import System.IO > let openFileWrite name = openFile name WriteMode > h :: IO Handle > h <- fmap openFileWrite getLine -- you need to type in a file name > > This looks wrong, because h presumably needs to be a fixed Handle. Being > an IO Handle seems to imply it is mutable. Haskell doesn't complain, though. > No it doesn't, nothing is "mutable" in Haskell, you can have IORef or STRef whose content can be mutated in the IO or ST monad but the IORef or STRef themselves won't be mutable. IO Handle is not "a mutable Handle", it's an IO action that returns an Handle... And that's exactly the type of h in your code ! That's because this code doesn't open anything, it read a line and thanks to fmap, it applies openFileWrite to this line, giving you an "IO Handle" in h, an action that would give you an Handle if it was executed... but it is not executed, it is just stocked in h. The type of "fmap openFileWrite getLine" is IO (IO Handle), not as you probably wanted IO Handle. As Bob said, if you want an Handle, you shouldn't use fmap but rather (>>=). Or you could do : act :: IO handle <- fmap openFileWrite getLine h :: Handle <- act but that's really not the usual way to do it (on the other hand it's interesting because it shows you that "IO a" are just values, you can manipulate them just like normal values. Basically your code was "correct", it just didn't give you an Handle (that would have been clear as soon as you tried to use h as an Handle) ! -- Jeda? -------------- next part -------------- An HTML attachment was scrubbed... URL: From martin.drautzburg at web.de Wed Mar 18 21:49:50 2015 From: martin.drautzburg at web.de (martin) Date: Wed, 18 Mar 2015 22:49:50 +0100 Subject: [Haskell-beginners] Finding the lowest element greater or equal than Message-ID: <5509F2FE.4030708@web.de> Hello all, I want to find the lowest element in a collection of items which is greatet or equal to a given element. There can be more than one such element in which case I wouldn't care which one I get. I still want to be able to iterate over the elements following the found element. In a way I want the equivalent of select ... from table where table.x > n How would I do this efficiently? I tried using an ordered list, but I would still have to traverse half the list on average. I suppose I can do this with some sort of tree, but i don't want to write all the code myself. But I couldn't find anything off the shelf. From k-bx at k-bx.com Wed Mar 18 22:07:27 2015 From: k-bx at k-bx.com (Konstantine Rybnikov) Date: Thu, 19 Mar 2015 00:07:27 +0200 Subject: [Haskell-beginners] Finding the lowest element greater or equal than In-Reply-To: <5509F2FE.4030708@web.de> References: <5509F2FE.4030708@web.de> Message-ID: Hi Martin, What you want depends on more details. If you just have a list of items, you can access its first item which is less than some "n" by doing: headMay (filter (< n) xs) Would this solution satisfy you? If not -- what condition would not be met? You mentioned something regarding that with ordered list you'd have to traverse half of the list on average. What did you mean by that? (I mean, if you have ordered list, then either its first element is what you need, or none of them are) On Wed, Mar 18, 2015 at 11:49 PM, martin wrote: > Hello all, > > I want to find the lowest element in a collection of items which is > greatet or equal to a given element. There can be > more than one such element in which case I wouldn't care which one I get. > I still want to be able to iterate over the > elements following the found element. In a way I want the equivalent of > > select ... > from table > where table.x > n > > > How would I do this efficiently? > > I tried using an ordered list, but I would still have to traverse half the > list on average. > > I suppose I can do this with some sort of tree, but i don't want to write > all the code myself. But I couldn't find > anything off the shelf. > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From bob at redivi.com Wed Mar 18 22:42:09 2015 From: bob at redivi.com (Bob Ippolito) Date: Wed, 18 Mar 2015 15:42:09 -0700 Subject: [Haskell-beginners] Finding the lowest element greater or equal than In-Reply-To: <5509F2FE.4030708@web.de> References: <5509F2FE.4030708@web.de> Message-ID: On Wed, Mar 18, 2015 at 2:49 PM, martin wrote: > > I want to find the lowest element in a collection of items which is > greatet or equal to a given element. There can be > more than one such element in which case I wouldn't care which one I get. > I still want to be able to iterate over the > elements following the found element. In a way I want the equivalent of > > select ... > from table > where table.x > n > > > How would I do this efficiently? > > I tried using an ordered list, but I would still have to traverse half the > list on average. > You could do it in log time (using a binary search algorithm) with an ordered Vector or Array. Lists are not an appropriate data structure for random access. > I suppose I can do this with some sort of tree, but i don't want to write > all the code myself. But I couldn't find > anything off the shelf. > Data.Map supports that operation in log time with splitLookup. You can use the values of the map to count the occurrences of a given element. If all of the elements are unique you can save a bit of space and use Data.Set instead, which has a splitMember function. -bob -------------- next part -------------- An HTML attachment was scrubbed... URL: From vale.cofershabica at gmail.com Fri Mar 20 19:52:46 2015 From: vale.cofershabica at gmail.com (Vale Cofer-Shabica) Date: Fri, 20 Mar 2015 15:52:46 -0400 Subject: [Haskell-beginners] suggestions for re-implementing mapM Message-ID: Hello all, I've been reading through "Tackling the Awkward Squad" [1] and am implementing the definitions "left as exercises" as I go. For section 2.2, I define: putLine :: [Char] -> IO () putLine :: mapM_ putChar where mapM_ :: Monad m => (a -> m b) -> a -> m () mapM_ f [] = return () mapM_ f (x:xs) = (f x) >> (mapM_ f xs) which works without difficulty. For the sake of learning, I decided to implement mapM as well. My definition (below) works, but seems really in-elegant. I checked the prelude source and found mapM defined in terms of sequence, which has some do-notation I'm not so clear on. I'm trying to avoid using do notation in my implementation because it still feels like magic. I'll work on de-sugaring do notation again once I have a solid handle on (>>=), (>>), and return. Any suggestions for cleaning this up would be much appreciated! mapM :: Monad m => (a -> m b) -> [a] -> m [b] mapM f [] = return [] mapM f (x:xs) = consMM (f x) (mapM f xs) consMM :: Monad m => m a -> m [a] -> m [a] consMM mx mxs = mx >>= ((flip consM) mxs) where consM x mxs = mxs>>=(\xs -> return (x:xs)) Thank you, vale [1] Suggested by apfelmus in a recent email to the list: http://research.microsoft.com/en-us/um/people/simonpj/papers/marktoberdorf/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From toad3k at gmail.com Fri Mar 20 20:07:56 2015 From: toad3k at gmail.com (David McBride) Date: Fri, 20 Mar 2015 16:07:56 -0400 Subject: [Haskell-beginners] suggestions for re-implementing mapM In-Reply-To: References: Message-ID: Sometimes it is easier to write it with do notation and then rewrite it back in normal terms: mapM :: Monad m => (a -> m b) -> [a] -> m [b] mapM _ [] = return [] mapM f (x:xs) = do x' <- f x xs' <- mapM f xs return $ x':xs' You can rewrite the second part step by step as: mapM f (x:xs) = f x >>= \x' -> mapM f xs >>= \xs' -> return (x' : xs') Also the base package does not use do notation. It defines it much more elegantly: mapM :: Monad m => (a -> m b) -> [a] -> m [b]mapM f as = sequence (map f as) On Fri, Mar 20, 2015 at 3:52 PM, Vale Cofer-Shabica < vale.cofershabica at gmail.com> wrote: > Hello all, > > I've been reading through "Tackling the Awkward Squad" [1] and am > implementing the definitions "left as exercises" as I go. For section 2.2, > I define: > > putLine :: [Char] -> IO () > putLine :: mapM_ putChar > > where > > mapM_ :: Monad m => (a -> m b) -> a -> m () > mapM_ f [] = return () > mapM_ f (x:xs) = (f x) >> (mapM_ f xs) > > which works without difficulty. For the sake of learning, I decided to > implement mapM as well. My definition (below) works, but seems really > in-elegant. I checked the prelude source and found mapM defined in terms of > sequence, which has some do-notation I'm not so clear on. I'm trying to > avoid using do notation in my implementation because it still feels like > magic. I'll work on de-sugaring do notation again once I have a solid > handle on (>>=), (>>), and return. Any suggestions for cleaning this up > would be much appreciated! > > mapM :: Monad m => (a -> m b) -> [a] -> m [b] > mapM f [] = return [] > mapM f (x:xs) = consMM (f x) (mapM f xs) > > consMM :: Monad m => m a -> m [a] -> m [a] > consMM mx mxs = mx >>= ((flip consM) mxs) where > consM x mxs = mxs>>=(\xs -> return (x:xs)) > > Thank you, > vale > > [1] Suggested by apfelmus in a recent email to the list: > http://research.microsoft.com/en-us/um/people/simonpj/papers/marktoberdorf/ > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From stuart.hungerford at gmail.com Fri Mar 20 21:39:37 2015 From: stuart.hungerford at gmail.com (Stuart Hungerford) Date: Sat, 21 Mar 2015 08:39:37 +1100 Subject: [Haskell-beginners] Multi-parameter type classes and ambiguous type variables... Message-ID: Hi, As a learning exercise I'm modelling some algebraic structures as Haskell typeclasses. Some of these are multi-parameter type classes. Here's a very simplified version of the type class relationships: class MM a where one :: a class AM a where zero :: a class (AM a, MM a) => SR a class (AM a) => AG a where inv :: a -> a class (SR a) => R a where neg :: a -> a class (R r, AG g) => M r g where sca :: r -> g -> g check :: (Eq g, M r g) => g -> Bool check x = sca one x == x The problem I have is that GHC is finding the "r" type variable in the "check" function ambiguous. Given my still limited Haskell knowledge I'm not surprised this is happening. What I would like to know is how experienced Haskellers handle this situation in practice: is there an idiomatic way of disambiguating "r" or is it a sign of poor type class design? Thanks, Stu From sumit.sahrawat.apm13 at iitbhu.ac.in Sat Mar 21 07:37:52 2015 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Sat, 21 Mar 2015 13:07:52 +0530 Subject: [Haskell-beginners] Multi-parameter type classes and ambiguous type variables... In-Reply-To: References: Message-ID: This might be better answered at the haskell-cafe. Sending to cafe. On 21 March 2015 at 03:09, Stuart Hungerford wrote: > Hi, > > As a learning exercise I'm modelling some algebraic structures as > Haskell typeclasses. Some of these are multi-parameter type classes. > Here's a very simplified version of the type class relationships: > > class MM a where > one :: a > > class AM a where > zero :: a > > class (AM a, MM a) => SR a > > class (AM a) => AG a where > inv :: a -> a > > class (SR a) => R a where > neg :: a -> a > > class (R r, AG g) => M r g where > sca :: r -> g -> g > > check :: (Eq g, M r g) => g -> Bool > check x = sca one x == x > > The problem I have is that GHC is finding the "r" type variable in the > "check" function ambiguous. Given my still limited Haskell knowledge > I'm not surprised this is happening. What I would like to know is how > experienced Haskellers handle this situation in practice: is there an > idiomatic way of disambiguating "r" or is it a sign of poor type class > design? > > Thanks, > > Stu > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -- Regards Sumit Sahrawat -------------- next part -------------- An HTML attachment was scrubbed... URL: From stuart.hungerford at gmail.com Sat Mar 21 20:15:52 2015 From: stuart.hungerford at gmail.com (Stuart Hungerford) Date: Sun, 22 Mar 2015 07:15:52 +1100 Subject: [Haskell-beginners] [Haskell-cafe] Multi-parameter type classes and ambiguous type variables... In-Reply-To: References: Message-ID: On Sat, Mar 21, 2015 at 7:31 PM, Chris Wong wrote: > [...] >>> check :: (Eq g, M r g) => g -> Bool >>> check x = sca one x == x >>> >>> The problem I have is that GHC is finding the "r" type variable in the >>> "check" function ambiguous. Given my still limited Haskell knowledge >>> I'm not surprised this is happening. What I would like to know is how >>> experienced Haskellers handle this situation in practice: is there an >>> idiomatic way of disambiguating "r" or is it a sign of poor type class >>> design? > > In the type signature: > > check :: (Eq g, M r g) => g -> Bool > > you fix the type `g`, but not the type `r`. This causes an ambiguity > in the program because if you had e.g. > > instance M Float Vector where ... > instance M Int Vector where ... > > both in the same program, and you passed a Vector to `check`, GHC > won't know which instance to choose. > > To solve this ambiguity, either fix `r` with an extra parameter: > > check :: (Eq g, M r g) => r -> g -> Bool > check one' x = sca one' x == x > > Or declare that `r` is uniquely determined by `g` using a *functional > dependency*: > > class (R r, AG g) => M r g | g -> r where > sca :: r -> g -> g > > Or equivalently, using *associated types*: > > class (AG g, R (Scalar g)) => M g where > type Scalar g :: * > sca :: Scalar g -> g -> g > > check :: (Eq g, M g) => g -> Bool > check x = -- as before > > A Google search for these two terms should yield plenty of tutorials > and examples. Thanks for this excellent explanation. > (By the way, I'd suggest using longer names like "Ring" and > "AdditiveGroup" instead, as they're easier to read.) Yes -- I stripped the example down, including the full names of the type classes, for explaining the issue. I could well have left the full names though. Stu From ram at rkrishnan.org Sun Mar 22 13:16:14 2015 From: ram at rkrishnan.org (Ramakrishnan Muthukrishnan) Date: Sun, 22 Mar 2015 18:46:14 +0530 Subject: [Haskell-beginners] Code review: Go challenge #1 in Haskell Message-ID: <1427030174.3627139.243629570.07376C30@webmail.messagingengine.com> Hello Haskellers: A few weeks ago, there was this thing called "Go challenge" and a problem was posted? on decoding a binary format and printing out the drum sequences in the input binary file. I made a Haskell solution and would love to get some code reviews. One of the input files given does not have the full bitstream and my program cannot parse that yet. I had been thinking about using a Monad transformer to make a `Get (Maybe) a' and output whatever it could parse and leave the rest behind, instead of failing completely. ? http://golang-challenge.com/go-challenge1/ (fwiw, the challenge is over.) Thanks in advance, Ramakrishnan From twashing at gmail.com Sun Mar 22 16:33:18 2015 From: twashing at gmail.com (Timothy Washington) Date: Sun, 22 Mar 2015 09:33:18 -0700 Subject: [Haskell-beginners] Dipping Toes Into Haskell In-Reply-To: References: Message-ID: So I've finally had a chance to revisit my tictactoe game. import Control.Lens data Piece = X | O | E deriving Show type Row = [Piece] type Board = [Row] *data Position = Int Int deriving Show* -- put an X or O in a position *move :: Board -> Piece -> Position -> Board* move board piece position = board main :: IO () main = putStrLn "Hello World" -- using Lenses -- https://github.com/ekmett/lens/wiki/Examples -- http://lens.github.io/tutorial.html -- http://blog.jakubarnold.cz/2014/07/14/lens-tutorial-introduction-part-1.html --let r1 = (E,E,E) --let r2 = (E,E,E) --let r3 = (E,E,E) --let board = (r1,r2,r3) Now, if I want to make a move, I'll want to set a *piece* on a *position*, on a *board*. Let's assume the board has the following shape. ?> let r1 = (E,E,E) ?> let r2 = (E,E,E) ?> let r3 = (E,E,E) ?> let board = (r1,r2,r3) ((E,E,E),(E,E,E),(E,E,E)) To return an updated board, I dug around and *i)* couldn't find a core Haskell equivalent to Clojure's update-in . *ii)* Zippers only deal with trees of left / right nodes. *iii)* So that left me with Control.Lens . Now I can easily inspect and update the board like so. ?> board^*._**2._1* E ?> set (*_2._1*) 42 board ((E,E,E),(42,E,E),(E,E,E)) I can then parameterize _2 or _1 like so. ?> let a = _2 ?> board ^. a (E,E,E) But I can't figure out how to include that parameter's type into a *Position* type definition. I've tried these unsuccessfully. *data Position = Int Int deriving Show -- original type definition* *data Position = Simple Lens (Int a) (Int a) deriving Show -- failing try 1* move :: Board -> Piece -> Position -> Board move board piece position = set (position) piece board -- want to use this instead of "set (*_2._1*) 42 board" Any ideas? :) Tim Washington Interruptsoftware.com On Thu, Mar 12, 2015 at 5:18 PM, Timothy Washington wrote: > Veeery nice. Thanks for your insights. > > The Typeclass stuff making a lot more sense now. And hence ghc-mod's > (Interactive-Haskell's) behaviour makes more sense to me. It's working like > a charm. > > I'll play around with nested list manipulation this evening. > > > Cheers > > Tim Washington > Interruptsoftware.com > > > On Thu, Mar 12, 2015 at 8:03 PM, Mike Meyer wrote: > >> On Thu, Mar 12, 2015 at 6:02 PM, Timothy Washington >> wrote: >> >>> To get started, I'm trying to implement a simple *tictactoe* game. And >>> I would like to be able to represent a Piece on the board, as either the >>> string "X" or "O". This is what I have so far. >>> >>> module Main where >>> >>> data Piece = X | O >>> type Row = [Piece] >>> type Board = [Row] >>> >>> -- put an X or O in a position >>> move :: Board -> Piece -> Board >>> move board piece = board >>> >>> -- check win vertically >>> -- check win horizontally >>> -- check win diagonally >>> >>> main :: IO () >>> main = putStrLn "Hello World" >>> >>> >>> >>> *A)* Now, I'd like to be able to *load code interactively*, preferably >>> within emacs. However I don't have access to my types with *ghci* or *ghc-mod >>> (Interactive-Haskell)*. In either case, this call fails with the below >>> error. >>> >>> >>> let p = Piece X >>> :20:9-13: Not in scope: data constructor `Piece' >>> >>> >> Piece is the data TYPE. It has two constructors, X, and O. If you load >> your module into ghci, you can do ":t X" to get the type of X, which is >> Piece. You want to do "let p = X" here. >> >> Check your mode docs while editing the haskell file. There should be a >> command to load the current buffer into a ghci running in an interactive >> emacs buffer. >> >> >>> *B)* And how do I make a *custom datatype* that's one of two strings >>> (enumeration of either "X" or "O"). Cabal builds and runs the abouve code, >>> so I know it can compile. But I'm confused as to where X or O is defined, >>> and how I would supply it as an input. >>> >> >> >> As noted, you can derive "Show" so that Piece types print as "X" and "O". >> Similarly, you can derive "Read": >> >> data Piece = X | O deriving (Show, Read) >> >> so that you can then read "X" and get back an X when the context calls >> for a Piece value: >> >> *Main> read "X" :: Piece >> >> X >> >> However, this isn't used a lot, as it tends to be slow and not very >> flexible for more complex types. For instance, it will let you read in >> lists of Pieces and lists of lists, but you'l lhave to use the list syntax, >> not something that looks like an actual board when printed. >> >> -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at webconect.ch Sun Mar 22 18:56:52 2015 From: lists at webconect.ch (Elias Diem) Date: Sun, 22 Mar 2015 19:56:52 +0100 Subject: [Haskell-beginners] Support for Maildir Message-ID: <20150322185652.GA5878@webconect.local> Hi there Am I right that there are no up-to-date packages/libraries to process email in Maildir format? -- Greetings Elias From hjgtuyl at chello.nl Sun Mar 22 22:25:32 2015 From: hjgtuyl at chello.nl (Henk-Jan van Tuyl) Date: Sun, 22 Mar 2015 23:25:32 +0100 Subject: [Haskell-beginners] Code review: Go challenge #1 in Haskell In-Reply-To: <1427030174.3627139.243629570.07376C30@webmail.messagingengine.com> References: <1427030174.3627139.243629570.07376C30@webmail.messagingengine.com> Message-ID: On Sun, 22 Mar 2015 14:16:14 +0100, Ramakrishnan Muthukrishnan wrote: > Hello Haskellers: > > A few weeks ago, there was this thing called "Go challenge" and a > problem was posted? on decoding a binary format and printing out the > drum sequences in the input binary file. > > I made a Haskell solution and would love to get some code reviews. > > in line put _ = do BinaryPut.putWord8 0 -- we don't care about writing the 'do' is not necessary, as there is only one action; you could also write: put _ = undefined -- we don't care about writing or: put _ = error "put is not implemented" The line (intercalate "\n" $ map show tracks') can be simplified to (unlines $ map show tracks') The line putStrLn (show (runGet get bs :: Splice)) can be simplified to print (runGet get bs :: Splice) as print is the same as putStrLn . show Instead of: else do track <- getTrack tracks' <- getTracks return (track:tracks') you could write: else liftM2 (:) getTrack getTracks or: else getTrack ^:^ getTracks where (^:^) = liftM2 (:) (import Control.Monad first) The function splitN is the same as chunksOf from the package split; I found this by entering the type of splitN as a search string in Hoogle. You can use hlint (from Hackage) to get some hints for possible improvements of the code. Regards, Henk-Jan van Tuyl -- Folding at home What if you could share your unused computer power to help find a cure? In just 5 minutes you can join the world's biggest networked computer and get us closer sooner. Watch the video. http://folding.stanford.edu/ http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html Haskell programming -- From ram at rkrishnan.org Mon Mar 23 01:16:12 2015 From: ram at rkrishnan.org (Ramakrishnan Muthukrishnan) Date: Mon, 23 Mar 2015 06:46:12 +0530 Subject: [Haskell-beginners] Code review: Go challenge #1 in Haskell In-Reply-To: References: <1427030174.3627139.243629570.07376C30@webmail.messagingengine.com> Message-ID: <1427073372.3755259.243804762.7CE52D5A@webmail.messagingengine.com> On Mon, Mar 23, 2015, at 03:55 AM, Henk-Jan van Tuyl wrote: > On Sun, 22 Mar 2015 14:16:14 +0100, Ramakrishnan Muthukrishnan > wrote: > > > Hello Haskellers: > > > > A few weeks ago, there was this thing called "Go challenge" and a > > problem was posted? on decoding a binary format and printing out the > > drum sequences in the input binary file. > > > > I made a Haskell solution and would love to get some code reviews. > > > > > > > in line > put _ = do BinaryPut.putWord8 0 -- we don't care about writing > the 'do' is not necessary, as there is only one action; > you could also write: > put _ = undefined -- we don't care about writing > or: > put _ = error "put is not implemented" > > > The line > (intercalate "\n" $ map show tracks') > can be simplified to > (unlines $ map show tracks') > > > The line > putStrLn (show (runGet get bs :: Splice)) > can be simplified to > print (runGet get bs :: Splice) > as print is the same as > putStrLn . show > > > Instead of: > else > do > track <- getTrack > tracks' <- getTracks > return (track:tracks') > you could write: > else liftM2 (:) getTrack getTracks > or: > else getTrack ^:^ getTracks > where > (^:^) = liftM2 (:) > (import Control.Monad first) Hello Henk-Jan, Thanks a lot for all the suggestions. > You can use hlint (from Hackage) to get some hints for possible > improvements of the code. Thanks. I ran HLint and it gave some more suggestions. Incorporated all the suggestions, thanks a lot. Ramakrishnan From hutch-lists at recursive.ca Mon Mar 23 11:57:58 2015 From: hutch-lists at recursive.ca (Bob Hutchison) Date: Mon, 23 Mar 2015 07:57:58 -0400 Subject: [Haskell-beginners] Dipping Toes Into Haskell In-Reply-To: References: Message-ID: Hi Tim, Staying from clojure? :-) > On Mar 22, 2015, at 12:33 PM, Timothy Washington wrote: > > So I've finally had a chance to revisit my tictactoe game. > > import Control.Lens > > data Piece = X | O | E deriving Show > type Row = [Piece] > type Board = [Row] > data Position = Int Int deriving Show > > -- put an X or O in a position > move :: Board -> Piece -> Position -> Board > move board piece position = board > > main :: IO () > main = putStrLn "Hello World" > > -- using Lenses > -- https://github.com/ekmett/lens/wiki/Examples > -- http://lens.github.io/tutorial.html > -- http://blog.jakubarnold.cz/2014/07/14/lens-tutorial-introduction-part-1.html > > --let r1 = (E,E,E) > --let r2 = (E,E,E) > --let r3 = (E,E,E) > --let board = (r1,r2,r3) > > Now, if I want to make a move, I'll want to set a piece on a position, on a board. Let's assume the board has the following shape. > > ?> let r1 = (E,E,E) > ?> let r2 = (E,E,E) > ?> let r3 = (E,E,E) > ?> let board = (r1,r2,r3) > ((E,E,E),(E,E,E),(E,E,E)) > > To return an updated board, I dug around and i) couldn't find a core Haskell equivalent to Clojure's update-in . ii) Zippers only deal with trees of left / right nodes. iii) So that left me with Control.Lens . Now I can easily inspect and update the board like so. Or you could use an two dimensional array of Positions instead (Data.Array). > > ?> board^._2._1 > E > ?> set (_2._1) 42 board > ((E,E,E),(42,E,E),(E,E,E)) > > I can then parameterize _2 or _1 like so. > > ?> let a = _2 > ?> board ^. a > (E,E,E) You can probably find the type of _1, _2, _3 in the repl, and use that in your code below. > > But I can't figure out how to include that parameter's type into a Position type definition. I've tried these unsuccessfully. > > data Position = Int Int deriving Show -- original type definition > data Position = Simple Lens (Int a) (Int a) deriving Show -- failing try 1 These are very suspicious. Did you intend to define constructors ?Int? and ?Simple?? Maybe you meant something like: data Position = Position Int Int deriving Show In which case you?ll have a type called ?Position? and a constructor with the same name. Cheers, Bob > > move :: Board -> Piece -> Position -> Board > move board piece position = set (position) piece board -- want to use this instead of "set (_2._1) 42 board" > > > Any ideas? > > > :) > > Tim Washington > Interruptsoftware.com > > > On Thu, Mar 12, 2015 at 5:18 PM, Timothy Washington > wrote: > Veeery nice. Thanks for your insights. > > The Typeclass stuff making a lot more sense now. And hence ghc-mod's (Interactive-Haskell's) behaviour makes more sense to me. It's working like a charm. > > I'll play around with nested list manipulation this evening. > > > Cheers > > Tim Washington > Interruptsoftware.com > > > On Thu, Mar 12, 2015 at 8:03 PM, Mike Meyer > wrote: > On Thu, Mar 12, 2015 at 6:02 PM, Timothy Washington > wrote: > To get started, I'm trying to implement a simple tictactoe game. And I would like to be able to represent a Piece on the board, as either the string "X" or "O". This is what I have so far. > > module Main where > > data Piece = X | O > type Row = [Piece] > type Board = [Row] > > -- put an X or O in a position > move :: Board -> Piece -> Board > move board piece = board > > -- check win vertically > -- check win horizontally > -- check win diagonally > > main :: IO () > main = putStrLn "Hello World" > > > A) Now, I'd like to be able to load code interactively, preferably within emacs. However I don't have access to my types with ghci or ghc-mod (Interactive-Haskell). In either case, this call fails with the below error. > > let p = Piece X > :20:9-13: Not in scope: data constructor `Piece' > > Piece is the data TYPE. It has two constructors, X, and O. If you load your module into ghci, you can do ":t X" to get the type of X, which is Piece. You want to do "let p = X" here. > > Check your mode docs while editing the haskell file. There should be a command to load the current buffer into a ghci running in an interactive emacs buffer. > > B) And how do I make a custom datatype that's one of two strings (enumeration of either "X" or "O"). Cabal builds and runs the abouve code, so I know it can compile. But I'm confused as to where X or O is defined, and how I would supply it as an input. > > > As noted, you can derive "Show" so that Piece types print as "X" and "O". Similarly, you can derive "Read": > > data Piece = X | O deriving (Show, Read) > > so that you can then read "X" and get back an X when the context calls for a Piece value: > *Main> read "X" :: Piece > > X > > > However, this isn't used a lot, as it tends to be slow and not very flexible for more complex types. For instance, it will let you read in lists of Pieces and lists of lists, but you'l lhave to use the list syntax, not something that looks like an actual board when printed. > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: From vale.cofershabica at gmail.com Mon Mar 23 19:03:15 2015 From: vale.cofershabica at gmail.com (Vale Cofer-Shabica) Date: Mon, 23 Mar 2015 15:03:15 -0400 Subject: [Haskell-beginners] suggestions for re-implementing mapM In-Reply-To: References: Message-ID: Thanks, David I appreciate the suggestions. vale On Fri, Mar 20, 2015 at 4:07 PM, David McBride wrote: > Sometimes it is easier to write it with do notation and then rewrite it > back in normal terms: > > mapM :: Monad m => (a -> m b) -> [a] -> m [b] > mapM _ [] = return [] > mapM f (x:xs) = do > x' <- f x > xs' <- mapM f xs > return $ x':xs' > > You can rewrite the second part step by step as: > > mapM f (x:xs) = f x >>= \x' -> mapM f xs >>= \xs' -> return (x' : xs') > > Also the base package does not use do notation. It defines it much more > elegantly: > > mapM :: Monad m => (a -> m b) -> [a] -> m [b]mapM f as = sequence (map f as) > > > > > On Fri, Mar 20, 2015 at 3:52 PM, Vale Cofer-Shabica < > vale.cofershabica at gmail.com> wrote: > >> Hello all, >> >> I've been reading through "Tackling the Awkward Squad" [1] and am >> implementing the definitions "left as exercises" as I go. For section 2.2, >> I define: >> >> putLine :: [Char] -> IO () >> putLine :: mapM_ putChar >> >> where >> >> mapM_ :: Monad m => (a -> m b) -> a -> m () >> mapM_ f [] = return () >> mapM_ f (x:xs) = (f x) >> (mapM_ f xs) >> >> which works without difficulty. For the sake of learning, I decided to >> implement mapM as well. My definition (below) works, but seems really >> in-elegant. I checked the prelude source and found mapM defined in terms of >> sequence, which has some do-notation I'm not so clear on. I'm trying to >> avoid using do notation in my implementation because it still feels like >> magic. I'll work on de-sugaring do notation again once I have a solid >> handle on (>>=), (>>), and return. Any suggestions for cleaning this up >> would be much appreciated! >> >> mapM :: Monad m => (a -> m b) -> [a] -> m [b] >> mapM f [] = return [] >> mapM f (x:xs) = consMM (f x) (mapM f xs) >> >> consMM :: Monad m => m a -> m [a] -> m [a] >> consMM mx mxs = mx >>= ((flip consM) mxs) where >> consM x mxs = mxs>>=(\xs -> return (x:xs)) >> >> Thank you, >> vale >> >> [1] Suggested by apfelmus in a recent email to the list: >> >> http://research.microsoft.com/en-us/um/people/simonpj/papers/marktoberdorf/ >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From martin.drautzburg at web.de Mon Mar 23 20:43:24 2015 From: martin.drautzburg at web.de (martin) Date: Mon, 23 Mar 2015 21:43:24 +0100 Subject: [Haskell-beginners] Arrow vs. function Message-ID: <55107AEC.6040705@web.de> Hello all I skimmed several Arrow tutorial and looked at the pretty diagrams and thought to myself "Hmm, these guys seem to take input and produce output". But that's what a function does. So what's the fundamental difference between an arrow and a fuction? From johnw at newartisans.com Mon Mar 23 20:57:29 2015 From: johnw at newartisans.com (John Wiegley) Date: Mon, 23 Mar 2015 15:57:29 -0500 Subject: [Haskell-beginners] Arrow vs. function In-Reply-To: <55107AEC.6040705@web.de> (martin's message of "Mon, 23 Mar 2015 21:43:24 +0100") References: <55107AEC.6040705@web.de> Message-ID: >>>>> martin writes: > But that's what a function does. So what's the fundamental difference > between an arrow and a fuction? Arrows abstract functions, allowing you to have constructions like Kleisli, which are Arrows, but compose in the presence of effects using (<=<) rather than (.). John From johnw at newartisans.com Mon Mar 23 21:11:44 2015 From: johnw at newartisans.com (John Wiegley) Date: Mon, 23 Mar 2015 16:11:44 -0500 Subject: [Haskell-beginners] Arrow vs. function In-Reply-To: (John Wiegley's message of "Mon, 23 Mar 2015 15:57:29 -0500") References: <55107AEC.6040705@web.de> Message-ID: >>>>> John Wiegley writes: > Arrows abstract functions, allowing you to have constructions like Kleisli, > which are Arrows, but compose in the presence of effects using (<=<) rather > than (.). That is, you compose them using (<<<) as you would using any other Arrow, but the Arrow instance is using a different form of composition under the hood. John From mike_k_houghton at yahoo.co.uk Mon Mar 23 22:06:15 2015 From: mike_k_houghton at yahoo.co.uk (Mike Houghton) Date: Mon, 23 Mar 2015 22:06:15 +0000 Subject: [Haskell-beginners] Mastermind Message-ID: <4152A3D0-082D-4485-976F-163B504FAEAB@yahoo.co.uk> Hi All, I?m working through http://www.seas.upenn.edu/~cis194/hw/02-lists.pdf - the homework for the CIS 194 Haskell course. I ?stuck? on question 6! If anyone has done this I?d really appreciate a pointer to solving it. The problem is, given these colors colors = [Red, Green, Blue, Yellow, Orange, Purple] we first need to be able to generate a list of all the codes, ie all length n combinations of the 6 colors. In general, Mastermind games use codes of length 4, however in theory the code could be any length. We have not yet made any assumptions about the lengths of the codes, so why start now? Your function should take in a length and return all Codes of that length: allCodes :: Int -> [Code] Hint: This exercise is a bit tricky. Try using a helper function that takes in all the codes of length n ? 1 and uses it to produce all codes of length n. You may find the concatMap function helpful. Now this [ [a,b,c,d] | a<-colors, b<-colors, c<-colors, d<-colors] will work for codes of length 4 but clearly doesn?t provide the general solution. I?m just not seeing it yet!!!! Thanks Mike -------------- next part -------------- An HTML attachment was scrubbed... URL: From raabe at froglogic.com Mon Mar 23 22:46:04 2015 From: raabe at froglogic.com (Frerich Raabe) Date: Mon, 23 Mar 2015 23:46:04 +0100 Subject: [Haskell-beginners] Mastermind In-Reply-To: <4152A3D0-082D-4485-976F-163B504FAEAB@yahoo.co.uk> References: <4152A3D0-082D-4485-976F-163B504FAEAB@yahoo.co.uk> Message-ID: <91bcc7caa1363aeb662e5cf31b440a22@roundcube.froglogic.com> Hi Mike, On 2015-03-23 23:06, Mike Houghton wrote: > I?m working through http://www.seas.upenn.edu/~cis194/hw/02-lists.pdf [1] - > the homework for the CIS 194 Haskell course. > I ?stuck? on question 6! > If anyone has done this I?d really appreciate a pointer to solving it. Just thinking out loud: Consider that to get all lists of length 2, you could add (e.g. prepend) each of the six colors to each of the lists of length 1. And to get each of the lists of length 1 you prepend each of the six colors to each of the lists of length 0. Does that help? :-) -- Frerich Raabe - raabe at froglogic.com www.froglogic.com - Multi-Platform GUI Testing From ngocdaothanh at gmail.com Mon Mar 23 22:57:46 2015 From: ngocdaothanh at gmail.com (Ngoc Dao) Date: Tue, 24 Mar 2015 07:57:46 +0900 Subject: [Haskell-beginners] Mastermind In-Reply-To: <91bcc7caa1363aeb662e5cf31b440a22@roundcube.froglogic.com> References: <4152A3D0-082D-4485-976F-163B504FAEAB@yahoo.co.uk> <91bcc7caa1363aeb662e5cf31b440a22@roundcube.froglogic.com> Message-ID: Mike, You may have noticed Frerich was saying about recursion. I will provide you some more topics/keywords so that you can investigate further: You should practise writing the recursion in 2 ways: normal recursion and tail recursion (to avoid stackoverflow when the recursion depth is large) For the tail recursion, you use the accumulator pattern, which is very common in functional programming. On Tue, Mar 24, 2015 at 7:46 AM, Frerich Raabe wrote: > Hi Mike, > > On 2015-03-23 23:06, Mike Houghton wrote: >> >> I?m working through http://www.seas.upenn.edu/~cis194/hw/02-lists.pdf [1] >> - the homework for the CIS 194 Haskell course. >> I ?stuck? on question 6! >> If anyone has done this I?d really appreciate a pointer to solving it. > > > Just thinking out loud: > > Consider that to get all lists of length 2, you could add (e.g. prepend) > each of the six colors to each of the lists of length 1. And to get each of > the lists of length 1 you prepend each of the six colors to each of the > lists of length 0. > > Does that help? :-) > > -- > Frerich Raabe - raabe at froglogic.com > www.froglogic.com - Multi-Platform GUI Testing > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From mike_k_houghton at yahoo.co.uk Mon Mar 23 23:13:46 2015 From: mike_k_houghton at yahoo.co.uk (Mike Houghton) Date: Mon, 23 Mar 2015 23:13:46 +0000 Subject: [Haskell-beginners] Mastermind In-Reply-To: References: <4152A3D0-082D-4485-976F-163B504FAEAB@yahoo.co.uk> <91bcc7caa1363aeb662e5cf31b440a22@roundcube.froglogic.com> Message-ID: <65AF3A76-44F2-46C9-82DD-D1E8B0FCEE4C@yahoo.co.uk> Thanks guys - I think the light has just gone on! ;) > On 23 Mar 2015, at 22:57, Ngoc Dao wrote: > > Mike, > > You may have noticed Frerich was saying about recursion. > I will provide you some more topics/keywords so that you can > investigate further: > > You should practise writing the recursion in 2 ways: > normal recursion and tail recursion (to avoid stackoverflow when the > recursion depth is large) > > For the tail recursion, you use the accumulator pattern, which is very > common in functional programming. > > On Tue, Mar 24, 2015 at 7:46 AM, Frerich Raabe wrote: >> Hi Mike, >> >> On 2015-03-23 23:06, Mike Houghton wrote: >>> >>> I?m working through http://www.seas.upenn.edu/~cis194/hw/02-lists.pdf [1] >>> - the homework for the CIS 194 Haskell course. >>> I ?stuck? on question 6! >>> If anyone has done this I?d really appreciate a pointer to solving it. >> >> >> Just thinking out loud: >> >> Consider that to get all lists of length 2, you could add (e.g. prepend) >> each of the six colors to each of the lists of length 1. And to get each of >> the lists of length 1 you prepend each of the six colors to each of the >> lists of length 0. >> >> Does that help? :-) >> >> -- >> Frerich Raabe - raabe at froglogic.com >> www.froglogic.com - Multi-Platform GUI Testing >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From michael at orlitzky.com Mon Mar 23 23:53:25 2015 From: michael at orlitzky.com (Michael Orlitzky) Date: Mon, 23 Mar 2015 19:53:25 -0400 Subject: [Haskell-beginners] Arrow vs. function In-Reply-To: <55107AEC.6040705@web.de> References: <55107AEC.6040705@web.de> Message-ID: <5510A775.8080700@orlitzky.com> On 03/23/2015 04:43 PM, martin wrote: > Hello all > > I skimmed several Arrow tutorial and looked at the pretty diagrams and thought to myself "Hmm, these guys seem to take > input and produce output". > > But that's what a function does. So what's the fundamental difference between an arrow and a fuction? They're basically functions, and you won't steer yourself wrong thinking about them like that. By analogy, in Haskell, if you wanted to add two floating point numbers you would need to define a floating point addition: floatAdd :: Float -> Float -> Float Then if you wanted to add two integers, you'd need a second function: intAdd :: Int -> Int -> Int The prelude already abstracts this away for you -- both Int and Float are instances of the Num class, which gives you, (+) :: (Num a) => a -> a -> a So at that point, you might ask yourself, what's the point of a Num? Aren't they just (floating point, int, etc.) numbers? The answer is "yes," and you don't want to have twenty different addition functions for everything that is some kind of number, so it makes sense to group all number-things into one typeclass. Likewise, all function-things are grouped into the Arrow typeclass so that you can compose them without worrying about the exact type. Everything in the Arrow typeclass is some kind of function, and you can compose them with the Arrow class methods. From ngocdaothanh at gmail.com Tue Mar 24 01:15:47 2015 From: ngocdaothanh at gmail.com (Ngoc Dao) Date: Tue, 24 Mar 2015 10:15:47 +0900 Subject: [Haskell-beginners] Mastermind In-Reply-To: <65AF3A76-44F2-46C9-82DD-D1E8B0FCEE4C@yahoo.co.uk> References: <4152A3D0-082D-4485-976F-163B504FAEAB@yahoo.co.uk> <91bcc7caa1363aeb662e5cf31b440a22@roundcube.froglogic.com> <65AF3A76-44F2-46C9-82DD-D1E8B0FCEE4C@yahoo.co.uk> Message-ID: Conceptually, you can think like this: * Recursion is the only way to loop in functional programming. * Things like map, filter, the sexy list comprehension etc. are just nice helpers to help you loop without having to write the recursion yourself. * When you can't see a straight forward way to use the helpers, you can always fall back to write the recursion yourself. It's a good exercise to spend about an hour to try to implement the map, filter etc. yourself, using recursion, to see what their implementations look like. On Tuesday, March 24, 2015, Mike Houghton wrote: > Thanks guys - I think the light has just gone on! > ;) > > > On 23 Mar 2015, at 22:57, Ngoc Dao > wrote: > > > > Mike, > > > > You may have noticed Frerich was saying about recursion. > > I will provide you some more topics/keywords so that you can > > investigate further: > > > > You should practise writing the recursion in 2 ways: > > normal recursion and tail recursion (to avoid stackoverflow when the > > recursion depth is large) > > > > For the tail recursion, you use the accumulator pattern, which is very > > common in functional programming. > > > > On Tue, Mar 24, 2015 at 7:46 AM, Frerich Raabe > wrote: > >> Hi Mike, > >> > >> On 2015-03-23 23:06, Mike Houghton wrote: > >>> > >>> I?m working through http://www.seas.upenn.edu/~cis194/hw/02-lists.pdf > [1] > >>> - the homework for the CIS 194 Haskell course. > >>> I ?stuck? on question 6! > >>> If anyone has done this I?d really appreciate a pointer to solving it. > >> > >> > >> Just thinking out loud: > >> > >> Consider that to get all lists of length 2, you could add (e.g. prepend) > >> each of the six colors to each of the lists of length 1. And to get > each of > >> the lists of length 1 you prepend each of the six colors to each of the > >> lists of length 0. > >> > >> Does that help? :-) > >> > >> -- > >> Frerich Raabe - raabe at froglogic.com > >> www.froglogic.com - Multi-Platform GUI Testing > >> _______________________________________________ > >> Beginners mailing list > >> Beginners at haskell.org > >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > _______________________________________________ > > Beginners mailing list > > Beginners at haskell.org > > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From twashing at gmail.com Tue Mar 24 02:38:24 2015 From: twashing at gmail.com (Timothy Washington) Date: Mon, 23 Mar 2015 19:38:24 -0700 Subject: [Haskell-beginners] Dipping Toes Into Haskell In-Reply-To: References: Message-ID: Hey man... On Mon, Mar 23, 2015 at 4:57 AM, Bob Hutchison wrote: > Hi Tim, > > Straying from clojure? :-) > > Lol, love it!! I'm a free spirit. Can't hold me down :) > On Mar 22, 2015, at 12:33 PM, Timothy Washington > wrote: > > So I've finally had a chance to revisit my tictactoe game. > > > import Control.Lens > > data Piece = X | O | E deriving Show > type Row = [Piece] > type Board = [Row] > *data Position = Int Int deriving Show* > > -- put an X or O in a position > *move :: Board -> Piece -> Position -> Board* > move board piece position = board > > main :: IO () > main = putStrLn "Hello World" > > Now, if I want to make a move, I'll want to set a *piece* on a *position*, > on a *board*. Let's assume the board has the following shape. > > ?> let r1 = (E,E,E) > ?> let r2 = (E,E,E) > ?> let r3 = (E,E,E) > ?> let board = (r1,r2,r3) > ((E,E,E),(E,E,E),(E,E,E)) > > > To return an updated board, I dug around and *i)* couldn't find a core > Haskell equivalent to Clojure's update-in > . *ii)* Zippers only deal > with trees of left / right nodes. *iii)* So that left me with Control.Lens > . Now I can easily inspect > and update the board like so. > > > Or you could use an two dimensional array of Positions instead > (Data.Array). > Hmm, probably. But the function's type signature below, seem to be the first order of business, no? > ?> board^*._**2._1* > E > ?> set (*_2._1*) 42 board > ((E,E,E),(42,E,E),(E,E,E)) > > > I can then parameterize _2 or _1 like so. > > ?> let a = _2 > ?> board ^. a > (E,E,E) > > > You can probably find the type of _1, _2, _3 in the repl, and use that in > your code below. > The types (:t ...) of both of these are: - a :: (Field2 s t a b, Functor f) => (a -> f b) -> s -> f t - _2 :: (Field2 s t a b, Functor f) => (a -> f b) -> s -> f t > But I can't figure out how to include that parameter's type into a > *Position* type definition. I've tried these unsuccessfully. > > *data Position = Int Int deriving Show -- original type definition* > *data Position = Simple Lens (Int a) (Int a) deriving Show -- failing try > 1* > > > These are very suspicious. Did you intend to define constructors ?Int? and > ?Simple?? Maybe you meant something like: > > data Position = Position Int Int deriving Show > > In which case you?ll have a type called ?Position? and a constructor with > the same name. > > Cheers, > Bob > > So ultimately I want a function signature that lets me pass in a lens position. -- 1. these 2 don't compile together data Position = Position Int Int deriving Show move :: Board -> Piece -> Position -> Board move board piece position = set (position) piece board -- 2. and using the (:t ...) type definition abouve, none of these work move :: Board -> Piece -> ((Field2 s t a b, Functor f) => (a -> f b) -> s -> f t) -> Board -- move :: Board -> Piece -> ((a -> f b) -> s -> f t) -> Board -- move :: Board -> Piece -> (a -> f b) -> Board -- move :: Board -> Piece -> (s -> f t) -> Board move board piece position = set (position) piece board -- 3. so the below code compiles, but doesn't do me much good... I need Position to be a lens, such that I can use A) *set (position) piece board* , instead of B) *set (_2._1) 42 board* module Main where import Control.Lens data Piece = X | O | E deriving Show type Row = [Piece] type Board = [Row] *data Position = Int Int deriving Show* *move :: Board -> Piece -> Position -> Board* move board piece position = board main :: IO () main = putStrLn "Hello World" Cheers mate :) Tim Washington Interruptsoftware.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From alt.mcarter at gmail.com Tue Mar 24 09:48:09 2015 From: alt.mcarter at gmail.com (Mark Carter) Date: Tue, 24 Mar 2015 09:48:09 +0000 Subject: [Haskell-beginners] Derived data Message-ID: <551132D9.4030103@gmail.com> I read inputs from files into various data types. Not all of the information is known at input time, so some of the data for a type needs to be derived. The question is: what is the best way of "guarding" between derived and underived data? By that I mean, there is a function which will derive missing data, and other functions can only work on derived data. Working on underived data would be a mistake. From mdorman at ironicdesign.com Tue Mar 24 10:21:22 2015 From: mdorman at ironicdesign.com (Michael Alan Dorman) Date: Tue, 24 Mar 2015 06:21:22 -0400 Subject: [Haskell-beginners] Derived data In-Reply-To: <551132D9.4030103@gmail.com> (Mark Carter's message of "Tue, 24 Mar 2015 09:48:09 +0000") References: <551132D9.4030103@gmail.com> Message-ID: <87k2y63dct.fsf@ironicdesign.com> Mark Carter writes: > I read inputs from files into various data types. Not all of the > information is known at input time, so some of the data for a type > needs to be derived. The question is: what is the best way of > "guarding" between derived and underived data? > > By that I mean, there is a function which will derive missing data, > and other functions can only work on derived data. Working on > underived data would be a mistake. That seems like the straight-up definition of two data types: data Raw = Raw (Maybe Int) Text (Maybe Text) data Cooked = Cooked Text oven :: Raw -> Cooked -- Can't pass Raw data to consumer consumer :: Cooked -> Result Mike. From hutch-lists at recursive.ca Tue Mar 24 13:13:03 2015 From: hutch-lists at recursive.ca (Bob Hutchison) Date: Tue, 24 Mar 2015 09:13:03 -0400 Subject: [Haskell-beginners] Dipping Toes Into Haskell In-Reply-To: References: Message-ID: > On Mar 23, 2015, at 10:38 PM, Timothy Washington wrote: > [snip] > So ultimately I want a function signature that lets me pass in a lens position. > > -- 1. these 2 don't compile together > > data Position = Position Int Int deriving Show > > move :: Board -> Piece -> Position -> Board > move board piece position = set (position) piece board > > > -- 2. and using the (:t ...) type definition abouve, none of these work > > move :: Board -> Piece -> ((Field2 s t a b, Functor f) => (a -> f b) -> s -> f t) -> Board > -- move :: Board -> Piece -> ((a -> f b) -> s -> f t) -> Board > -- move :: Board -> Piece -> (a -> f b) -> Board > -- move :: Board -> Piece -> (s -> f t) -> Board > > move board piece position = set (position) piece board > > -- 3. so the below code compiles, but doesn't do me much good... I need Position to be a lens, such that I can use A) set (position) piece board , instead of B) set (_2._1) 42 board > > module Main where > > import Control.Lens > > data Piece = X | O | E deriving Show > type Row = [Piece] > type Board = [Row] > data Position = Int Int deriving Show > > move :: Board -> Piece -> Position -> Board > move board piece position = board You seem set on lenses. So if you write that move function like this (in case anyone?s wondering, I happen to know this isn?t a homework question): data Piece = X | O | E deriving Show move :: a -> b1 -> ASetter a b a1 b1 -> b move board position piece = board & position .~ piece This?ll work. But how are you going to get the position? If you?re given an integer based coordinate, as you seem to want from your definitions of Position, then you?re going to have to do something ugly. Why not just go with an array and be done with it? Something like this (with your original definition of Piece): import Data.Array data Piece' = X | O | E deriving Show type Position' = (Int,Int) type Board' = Array Position? Piece' board' :: Board' board' = array ((1,1),(3,3)) [((i,j), E) | i <- [1,2,3], j <- [1,2,3]] move' :: Board' -> Piece' -> Position' -> Board' move' board piece pos = board // [(pos, piece)] If you want a slightly less ugly of looking at the board import qualified Data.List.Split as S pp board = mapM_ print $ S.chunksOf 3 $ elems board will display the board something like: [E,E,E] [E,E,E] [E,E,E] I hope I didn?t say too much. Cheers, Bob > > main :: IO () > main = putStrLn "Hello World" > > > > Cheers mate :) > > Tim Washington > Interruptsoftware.com > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners From shishir.srivastava at gmail.com Tue Mar 24 13:24:28 2015 From: shishir.srivastava at gmail.com (Shishir Srivastava) Date: Tue, 24 Mar 2015 13:24:28 +0000 Subject: [Haskell-beginners] Haskell Compiler Message-ID: Hi, What language is the Haskell compiler writter in ? Is it in Haskell itself just like gcc is written in 'C' ? Thanks, Shishir Srivastava -------------- next part -------------- An HTML attachment was scrubbed... URL: From sumit.sahrawat.apm13 at iitbhu.ac.in Tue Mar 24 13:26:10 2015 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Tue, 24 Mar 2015 18:56:10 +0530 Subject: [Haskell-beginners] Haskell Compiler In-Reply-To: References: Message-ID: https://github.com/ghc/ghc It's written in haskell. And a lot of other stuff (including C). On 24 March 2015 at 18:54, Shishir Srivastava wrote: > Hi, > > What language is the Haskell compiler writter in ? Is it in Haskell itself > just like gcc is written in 'C' ? > > Thanks, > Shishir Srivastava > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -- Regards Sumit Sahrawat -------------- next part -------------- An HTML attachment was scrubbed... URL: From abahadirdogan at gmail.com Tue Mar 24 13:32:26 2015 From: abahadirdogan at gmail.com (=?UTF-8?B?QmFoYWTEsXIgRG/En2Fu?=) Date: Tue, 24 Mar 2015 15:32:26 +0200 Subject: [Haskell-beginners] Haskell Compiler In-Reply-To: References: Message-ID: For a deeper understanding: http://www.aosabook.org/en/ghc.html On Tue, Mar 24, 2015 at 3:24 PM, Shishir Srivastava < shishir.srivastava at gmail.com> wrote: > Hi, > > What language is the Haskell compiler writter in ? Is it in Haskell itself > just like gcc is written in 'C' ? > > Thanks, > Shishir Srivastava > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mwm at mired.org Tue Mar 24 13:40:21 2015 From: mwm at mired.org (Mike Meyer) Date: Tue, 24 Mar 2015 08:40:21 -0500 Subject: [Haskell-beginners] Haskell Compiler In-Reply-To: References: Message-ID: There's more than one Haskell compiler, just like there's more than one C compiler. As others have noted, the most popular one (ghc) is written in haskell. You can find a list of implementations in the wiki: https://wiki.haskell.org/Implementations. On Tue, Mar 24, 2015 at 8:24 AM, Shishir Srivastava < shishir.srivastava at gmail.com> wrote: > Hi, > > What language is the Haskell compiler writter in ? Is it in Haskell itself > just like gcc is written in 'C' ? > > Thanks, > Shishir Srivastava > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From twashing at gmail.com Wed Mar 25 03:37:42 2015 From: twashing at gmail.com (Timothy Washington) Date: Tue, 24 Mar 2015 20:37:42 -0700 Subject: [Haskell-beginners] Dipping Toes Into Haskell In-Reply-To: References: Message-ID: Crickey. You're still the man, lol :) On Tue, Mar 24, 2015 at 6:13 AM, Bob Hutchison wrote: > > > On Mar 23, 2015, at 10:38 PM, Timothy Washington > wrote: > > > > [snip] > > ... > > You seem set on lenses. So if you write that move function like this (in > case anyone?s wondering, I happen to know this isn?t a homework question): > > data Piece = X | O | E deriving Show > > move :: a -> b1 -> ASetter a b a1 b1 -> b > move board position piece = board & position .~ piece > > This?ll work. But how are you going to get the position? If you?re given > an integer based coordinate, as you seem to want from your definitions of > Position, then you?re going to have to do something ugly. > This is a good point. I'm not particularly attached to lenses. That was just the conclusion I reached, in order to reach into and manipulate my original nested lists. I didn't see a way to do nested list updates in Data.List, on hackage . But now I see the difference between that and Data.Array (indexable, etc). I'll come back to Lenses later on, just because now I'm curious. I'm happy for the Position to be "*data Position = SomeLensType SomeLensType deriving Show*", where "*:t _2 => SomeLensType*". Or something else that accommodates lens' data types.... but baby steps :) Why not just go with an array and be done with it? Something like this > (with your original definition of Piece): > > import Data.Array > > data Piece' = X | O | E deriving Show > type Position' = (Int,Int) > type Board' = Array Position? Piece' > > board' :: Board' > board' = array ((1,1),(3,3)) [((i,j), E) | i <- [1,2,3], j <- [1,2,3]] > > move' :: Board' -> Piece' -> Position' -> Board' > move' board piece pos = board // [(pos, piece)] > This works swimmingly. So excellent point. If you want a slightly less ugly of looking at the board > > import qualified Data.List.Split as S > > pp board = mapM_ print $ S.chunksOf 3 $ elems board > > will display the board something like: > > [E,E,E] > [E,E,E] > [E,E,E] > > I hope I didn?t say too much. > Not at all. These are exactly the kinds of hints that I need. In fact, with the *//* and *array* functions, this makes a lot of sense. And I used that and the board beautifier chunk, to create this. import Data.Array import qualified Data.List.Split as S data Piece' = X | O | E deriving Show type Position' = (Int,Int) type Board' = Array Position' Piece' board' :: Board' board' = array ((1,1),(3,3)) [((i,j), E) | i <- [1,2,3], j <- [1,2,3]] ppb' :: Board' -> IO() ppb' b = mapM_ print $ S.chunksOf 3 $ elems b move' :: Board' -> Piece' -> Position' -> Board' move' board piece pos = board // [(pos, piece)] Now, I can pass in the board, piece, and position, to get my expected result. ?> board' array ((1,1),(3,3)) [((1,1),E),((1,2),E),((1,3),E),((2,1),E),((2,2),E),((2,3),E),((3,1),E),((3,2),E),((3,3),E)] ?> let b1 = move' board' *X* (1,3) ?> b1 array ((1,1),(3,3)) [((1,1),E),((1,2),E),((1,3),X),((2,1),E),((2,2),E),((2,3),E),((3,1),E),((3,2),E),((3,3),E)] ?> ppb' b1 [E,E,*X*] [E,E,E] [E,E,E] Cheers, > Bob Cool ! Cheers :) Tim Washington Interruptsoftware.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From shishir.srivastava at gmail.com Wed Mar 25 13:55:11 2015 From: shishir.srivastava at gmail.com (Shishir Srivastava) Date: Wed, 25 Mar 2015 13:55:11 +0000 Subject: [Haskell-beginners] Empty list Message-ID: Hi, Can someone please explain why this results in error - [] `elem` [1,2,3] Shouldn't the empty set by definition be the element of all sets including a non-empty set ? I am assuming 'Lists' are different from 'Sets' in Haskell, if yes, is there a separate module for dealing/working with sets ? Thanks, Shishir Srivastava -------------- next part -------------- An HTML attachment was scrubbed... URL: From timmelzer at gmail.com Wed Mar 25 14:00:02 2015 From: timmelzer at gmail.com (Norbert Melzer) Date: Wed, 25 Mar 2015 15:00:02 +0100 Subject: [Haskell-beginners] Empty list In-Reply-To: References: Message-ID: You are correct, a list is not a set. A list is a list of things, that can be there multiple times. A set is a set of things, where nothing can be twice. So take a look at Data.Set Am 25.03.2015 14:55 schrieb "Shishir Srivastava" < shishir.srivastava at gmail.com>: > Hi, > > Can someone please explain why this results in error - > > [] `elem` [1,2,3] > > Shouldn't the empty set by definition be the element of all sets including > a non-empty set ? > > I am assuming 'Lists' are different from 'Sets' in Haskell, if yes, is > there a separate module for dealing/working with sets ? > > Thanks, > Shishir Srivastava > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From shishir.srivastava at gmail.com Wed Mar 25 14:02:34 2015 From: shishir.srivastava at gmail.com (Shishir Srivastava) Date: Wed, 25 Mar 2015 14:02:34 +0000 Subject: [Haskell-beginners] Monoids and Groups Message-ID: Hi, Reading about Monoids it seems they derive a lot on the algebraic structures of 'Groups' ? Is it then correct to assume that Monoids can be used to represent 'Groups' ? If not are there any standard haskell libraries which represent algebraic structures such as 'Groups' , 'Fields' etc. Thanks, Shishir Srivastava -------------- next part -------------- An HTML attachment was scrubbed... URL: From allbery.b at gmail.com Wed Mar 25 14:03:29 2015 From: allbery.b at gmail.com (Brandon Allbery) Date: Wed, 25 Mar 2015 10:03:29 -0400 Subject: [Haskell-beginners] Empty list In-Reply-To: References: Message-ID: On Wed, Mar 25, 2015 at 10:00 AM, Norbert Melzer wrote: > You are correct, a list is not a set. A list is a list of things, that can > be there multiple times. A set is a set of things, where nothing can be > twice. So take a look at Data.Set > Note that this won't actually solve the original problem; Haskell is an implementation of a strongly typed lambda calculus, not of number theory, and Haskell collections cannot (easily) contain elements of different types --- so the empty set is not an element of a set, and the empty list is not an element of a list. -- brandon s allbery kf8nh sine nomine associates allbery.b at gmail.com ballbery at sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From allbery.b at gmail.com Wed Mar 25 14:07:17 2015 From: allbery.b at gmail.com (Brandon Allbery) Date: Wed, 25 Mar 2015 10:07:17 -0400 Subject: [Haskell-beginners] Monoids and Groups In-Reply-To: References: Message-ID: On Wed, Mar 25, 2015 at 10:02 AM, Shishir Srivastava < shishir.srivastava at gmail.com> wrote: > Reading about Monoids it seems they derive a lot on the algebraic > structures of 'Groups' ? > A monoid is a semigroup with an identity element, and as such inherits much of its behavior from semigroups. For historical reasons, a Haskell Monoid is not based on a notional Haskell Semigroup. There are packages that add semigroups and other algebraic structures, and even alternative Preludes that provide a reasonably complete set of algebraic structures. Every so often you'll see bikeshedding in the Haskell community over whether the default Prelude should provide some or all of these. :) -- brandon s allbery kf8nh sine nomine associates allbery.b at gmail.com ballbery at sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From mwm at mired.org Wed Mar 25 14:07:16 2015 From: mwm at mired.org (Mike Meyer) Date: Wed, 25 Mar 2015 09:07:16 -0500 Subject: [Haskell-beginners] Empty list In-Reply-To: References: Message-ID: On Wed, Mar 25, 2015 at 8:55 AM, Shishir Srivastava < shishir.srivastava at gmail.com> wrote: > Hi, > > Can someone please explain why this results in error - > > [] `elem` [1,2,3] > > Shouldn't the empty set by definition be the element of all sets including > a non-empty set ? > Norbert gave you the information about Lists and Data.Set, but you're wrong about the properties of the empty set. The empty set is a SUBSET of all sets. But it's only a MEMBER of supersets of {{}}. -------------- next part -------------- An HTML attachment was scrubbed... URL: From joel.s.williamson at gmail.com Wed Mar 25 14:10:05 2015 From: joel.s.williamson at gmail.com (Joel Williamson) Date: Wed, 25 Mar 2015 14:10:05 +0000 Subject: [Haskell-beginners] Empty list In-Reply-To: References: Message-ID: Shishir, you need to distinguish between membership (1 is an element of [1,2,3], [] is not) and subsets (both [1] and [] are subsets of [1,2,3]). elem checks the first property, intersection checks the second. On Wed, 25 Mar 2015 10:03 Brandon Allbery wrote: > On Wed, Mar 25, 2015 at 10:00 AM, Norbert Melzer > wrote: > >> You are correct, a list is not a set. A list is a list of things, that >> can be there multiple times. A set is a set of things, where nothing can be >> twice. So take a look at Data.Set >> > > Note that this won't actually solve the original problem; Haskell is an > implementation of a strongly typed lambda calculus, not of number theory, > and Haskell collections cannot (easily) contain elements of different types > --- so the empty set is not an element of a set, and the empty list is not > an element of a list. > > -- > brandon s allbery kf8nh sine nomine > associates > allbery.b at gmail.com > ballbery at sinenomine.net > unix, openafs, kerberos, infrastructure, xmonad > http://sinenomine.net > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mwm at mired.org Wed Mar 25 14:11:07 2015 From: mwm at mired.org (Mike Meyer) Date: Wed, 25 Mar 2015 09:11:07 -0500 Subject: [Haskell-beginners] Empty list In-Reply-To: References: Message-ID: On Wed, Mar 25, 2015 at 9:03 AM, Brandon Allbery wrote: > On Wed, Mar 25, 2015 at 10:00 AM, Norbert Melzer > wrote: > >> You are correct, a list is not a set. A list is a list of things, that >> can be there multiple times. A set is a set of things, where nothing can be >> twice. So take a look at Data.Set >> > > Note that this won't actually solve the original problem; Haskell is an > implementation of a strongly typed lambda calculus, not of number theory, > and Haskell collections cannot (easily) contain elements of different types > --- so the empty set is not an element of a set, and the empty list is not > an element of a list. > Did you forget a couple of "necessarily"'s? Prelude Data.Set> [] `elem` [[]] True Prelude Data.Set> empty `member` (insert empty empty) True -------------- next part -------------- An HTML attachment was scrubbed... URL: From max.voit+mlhb at with-eyes.net Wed Mar 25 14:12:49 2015 From: max.voit+mlhb at with-eyes.net (Max Voit) Date: Wed, 25 Mar 2015 15:12:49 +0100 Subject: [Haskell-beginners] Empty list In-Reply-To: References: Message-ID: <20150325151249.6f13bb54@veeloqu.lan> Hi Shishir, (in the following I'm ignoring the problem that lists have order and elements may be in there multiple times) On Wed, 25 Mar 2015 13:55:11 +0000 Shishir Srivastava wrote: > Shouldn't the empty set by definition be the element of all sets > including a non-empty set ? This is not even true in the mathematical sense. True are: a) all power sets include the empty set as an *element* b) the empty set is a *subset* of all sets For case (a) you'd need a list of lists since a powerset is a set of sets. For (b) `elem` is not the correct function. Max From adam at adamflott.com Wed Mar 25 15:37:52 2015 From: adam at adamflott.com (Adam Flott) Date: Wed, 25 Mar 2015 11:37:52 -0400 Subject: [Haskell-beginners] parsec and a never terminating parser Message-ID: <20150325113752.a6e3f7256ffb4fe9fecb6ddb@adamflott.com> I'm having trouble understanding why my simple parser never terminates when specific input is used. For example, let's say the first column is a field which can be in one of 4 states, empty, omitted, other, and any arbitrary value. That is, data FieldState a = EmptyState | OmittedState | OtherState | FullState a deriving (Eq, Ord) When attempting to use, $ echo "- " | ./parser "- \n" empty ('-') $ echo "^ " | ./parser "^ \n" omitted ('^') $ echo "~ " | ./parser "~ \n" other ('~') [ all of this is as expected ] $ echo "1 " | ./parser "1 \n" [ computer twiddles it's thumbs here until I manually terminate it ... ] ^C^C $ Does anyone know what's happening and now to alleviate it? -- begin full code -- -- base import Control.Applicative import Data.Word -- Hackage import qualified Data.Text.Lazy as TL import qualified Data.Text.Lazy.IO as TLIO import Text.Parsec (parse) import Text.Parsec.Text.Lazy (Parser) import Text.Parser.Combinators import Text.Parser.Char data FieldState a = EmptyState | OmittedState | OtherState | FullState a deriving (Eq, Ord) instance Functor FieldState where fmap f (FullState a) = FullState (f a) fmap _ EmptyState = EmptyState fmap _ OmittedState = OmittedState fmap _ OtherState = OtherState instance Applicative FieldState where pure = FullState (FullState f) <*> (FullState x) = FullState (f x) _ <*> _ = EmptyState instance Monad FieldState where (FullState x) >>= k = k x EmptyState >>= _ = EmptyState OmittedState >>= _ = OmittedState OtherState >>= _ = OtherState (FullState _) >> k = k EmptyState >> _ = EmptyState OmittedState >> _ = OmittedState OtherState >> _ = OtherState return = FullState fail _ = EmptyState instance Show (FieldState x) where show (EmptyState) = "empty ('-')" show (OmittedState) = "omitted ('^')" show (OtherState) = "other ('~')" show x' = show x' data Counter = Counter Word64 deriving (Eq, Ord, Show) parseNum :: (Num a) => Parser a parseNum = do n <- rd <$> many digit return $ fromIntegral n where rd = read :: String -> Integer parseCounter :: Parser Counter parseCounter = Counter <$> parseNum parseFieldStateOff :: Parser Char parseFieldStateOff = char '-' parseFieldStateOmitted :: Parser Char parseFieldStateOmitted = char '^' parseFieldStateOther :: Parser Char parseFieldStateOther = char '~' parseFieldState :: Parser a -> Parser (FieldState a) parseFieldState p = (parseFieldStateOff >> return EmptyState) <|> (parseFieldStateOmitted >> return OmittedState) <|> (parseFieldStateOther >> return OtherState) <|> (p >>= return . FullState) main :: IO () main = do ls <- TLIO.getContents print ls mapM_ processLine (TL.lines ls) processLine :: TL.Text -> IO () processLine line = case (parse (parseFieldState parseCounter) "" line) of Left err -> print err Right xs -> print xs -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 490 bytes Desc: not available URL: From martin.drautzburg at web.de Wed Mar 25 17:51:48 2015 From: martin.drautzburg at web.de (martin) Date: Wed, 25 Mar 2015 18:51:48 +0100 Subject: [Haskell-beginners] Open-ended list comprehension Message-ID: <5512F5B4.80203@web.de> Hello all, when I write my own recursions, I often end up with something like a : b : c : (f x) where f x returns a list. I assume this avoids the costly (++) function, right? But when I use list comprehensions I always get a complete list and it is costly to append something to it. How can I use the power of list comprehensions, but return an [a]->[a] instead of an [a]? Is this a good idea at all, or will I pile up thunks? From idivyanshu.ranjan at gmail.com Wed Mar 25 18:00:54 2015 From: idivyanshu.ranjan at gmail.com (divyanshu ranjan) Date: Wed, 25 Mar 2015 23:30:54 +0530 Subject: [Haskell-beginners] Open-ended list comprehension In-Reply-To: <5512F5B4.80203@web.de> References: <5512F5B4.80203@web.de> Message-ID: Hi martin, Check dlist (https://hackage.haskell.org/package/dlist-0.7.1.1). On Wed, Mar 25, 2015 at 11:21 PM, martin wrote: > Hello all, > > when I write my own recursions, I often end up with something like > > a : b : c : (f x) > > where f x returns a list. I assume this avoids the costly (++) function, > right? > > But when I use list comprehensions I always get a complete list and it is > costly to append something to it. How can I > use the power of list comprehensions, but return an [a]->[a] instead of an > [a]? > > Is this a good idea at all, or will I pile up thunks? > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From martin.drautzburg at web.de Wed Mar 25 18:20:43 2015 From: martin.drautzburg at web.de (martin) Date: Wed, 25 Mar 2015 19:20:43 +0100 Subject: [Haskell-beginners] Open-ended list comprehension In-Reply-To: References: <5512F5B4.80203@web.de> Message-ID: <5512FC7B.8040407@web.de> Am 03/25/2015 um 07:00 PM schrieb divyanshu ranjan: > Hi martin, > > Check dlist (https://hackage.haskell.org/package/dlist-0.7.1.1). I cannot see how I can create a dlist via a list comprehension, other than running fromList. But I assume this already has o(n) complexity. It may pay after several appends, though. What I am looking for is, if I have: veryLongList = [x | x <- ...] how can I use list a comprehension and end up with a dlist? > > On Wed, Mar 25, 2015 at 11:21 PM, martin > wrote: > > Hello all, > > when I write my own recursions, I often end up with something like > > a : b : c : (f x) > > where f x returns a list. I assume this avoids the costly (++) function, right? > > But when I use list comprehensions I always get a complete list and it is costly to append something to it. How can I > use the power of list comprehensions, but return an [a]->[a] instead of an [a]? > > Is this a good idea at all, or will I pile up thunks? > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > From marcin.jan.mrotek at gmail.com Wed Mar 25 18:42:06 2015 From: marcin.jan.mrotek at gmail.com (Marcin Mrotek) Date: Wed, 25 Mar 2015 19:42:06 +0100 Subject: [Haskell-beginners] Open-ended list comprehension In-Reply-To: <5512FC7B.8040407@web.de> References: <5512F5B4.80203@web.de> <5512FC7B.8040407@web.de> Message-ID: Hello, DList is a monad, so you can use them like lists with the MonadComprehensions extension. Alternatively, make use of the MonadPlus functions, which give you the same power without the nice syntax. Best regards, Marcin MRotek From toad3k at gmail.com Wed Mar 25 21:10:00 2015 From: toad3k at gmail.com (David McBride) Date: Wed, 25 Mar 2015 17:10:00 -0400 Subject: [Haskell-beginners] parsec and a never terminating parser In-Reply-To: <20150325113752.a6e3f7256ffb4fe9fecb6ddb@adamflott.com> References: <20150325113752.a6e3f7256ffb4fe9fecb6ddb@adamflott.com> Message-ID: The problem is your show instance. show x' = show x', means that when x' is a FullState, it shows it, which causes an infinite loop. You need to take out the default case and add something for FullState. On Wed, Mar 25, 2015 at 11:37 AM, Adam Flott wrote: > I'm having trouble understanding why my simple parser never terminates when > specific input is used. > > For example, let's say the first column is a field which can be in one of 4 > states, empty, omitted, other, and any arbitrary value. That is, > > data FieldState a = EmptyState | OmittedState | OtherState | FullState > a > deriving (Eq, Ord) > > When attempting to use, > > $ echo "- " | ./parser > "- \n" > empty ('-') > $ echo "^ " | ./parser > "^ \n" > omitted ('^') > $ echo "~ " | ./parser > "~ \n" > other ('~') > [ all of this is as expected ] > $ echo "1 " | ./parser > "1 \n" > [ computer twiddles it's thumbs here until I manually terminate it ... > ] > ^C^C > $ > > Does anyone know what's happening and now to alleviate it? > > > -- begin full code -- > > -- base > import Control.Applicative > import Data.Word > > -- Hackage > import qualified Data.Text.Lazy as TL > import qualified Data.Text.Lazy.IO as TLIO > import Text.Parsec (parse) > import Text.Parsec.Text.Lazy (Parser) > import Text.Parser.Combinators > import Text.Parser.Char > > data FieldState a = EmptyState | OmittedState | OtherState | FullState a > deriving (Eq, Ord) > > instance Functor FieldState where > fmap f (FullState a) = FullState (f a) > fmap _ EmptyState = EmptyState > fmap _ OmittedState = OmittedState > fmap _ OtherState = OtherState > > instance Applicative FieldState where > pure = FullState > (FullState f) <*> (FullState x) = FullState (f x) > _ <*> _ = EmptyState > > instance Monad FieldState where > (FullState x) >>= k = k x > EmptyState >>= _ = EmptyState > OmittedState >>= _ = OmittedState > OtherState >>= _ = OtherState > > (FullState _) >> k = k > EmptyState >> _ = EmptyState > OmittedState >> _ = OmittedState > OtherState >> _ = OtherState > > return = FullState > fail _ = EmptyState > > instance Show (FieldState x) where > show (EmptyState) = "empty ('-')" > show (OmittedState) = "omitted ('^')" > show (OtherState) = "other ('~')" > show x' = show x' > > data Counter = Counter Word64 deriving (Eq, Ord, Show) > > parseNum :: (Num a) => Parser a > parseNum = do > n <- rd <$> many digit > return $ fromIntegral n > where rd = read :: String -> Integer > > parseCounter :: Parser Counter > parseCounter = Counter <$> parseNum > > parseFieldStateOff :: Parser Char > parseFieldStateOff = char '-' > > parseFieldStateOmitted :: Parser Char > parseFieldStateOmitted = char '^' > > parseFieldStateOther :: Parser Char > parseFieldStateOther = char '~' > > parseFieldState :: Parser a -> Parser (FieldState a) > parseFieldState p = (parseFieldStateOff >> return EmptyState) > <|> (parseFieldStateOmitted >> return OmittedState) > <|> (parseFieldStateOther >> return OtherState) > <|> (p >>= return . FullState) > > main :: IO () > main = do > ls <- TLIO.getContents > print ls > mapM_ processLine (TL.lines ls) > > processLine :: TL.Text -> IO () > processLine line = case (parse (parseFieldState parseCounter) "" line) of > Left err -> print err > Right xs -> print xs > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From adam at adamflott.com Wed Mar 25 21:53:46 2015 From: adam at adamflott.com (Adam Flott) Date: Wed, 25 Mar 2015 17:53:46 -0400 Subject: [Haskell-beginners] parsec and a never terminating parser In-Reply-To: References: <20150325113752.a6e3f7256ffb4fe9fecb6ddb@adamflott.com> Message-ID: <20150325175346.3681c6cce129f507c8d1a769@adamflott.com> On Wed, 25 Mar 2015 17:10:00 -0400 David McBride wrote: > The problem is your show instance. > > show x' = show x', means that when x' is a FullState, it shows it, which > causes an infinite loop. > > You need to take out the default case and add something for FullState. > Doh! Nice catch. Thanks David! For those keeping track, here's how to fix such a case: instance Show x => Show (FieldState x) where show (EmptyState) = "empty ('-')" show (OmittedState) = "omitted ('^')" show (OtherState) = "other ('~')" show (FullState x') = show x' > On Wed, Mar 25, 2015 at 11:37 AM, Adam Flott wrote: > > > I'm having trouble understanding why my simple parser never terminates when > > specific input is used. > > > > For example, let's say the first column is a field which can be in one of 4 > > states, empty, omitted, other, and any arbitrary value. That is, > > > > data FieldState a = EmptyState | OmittedState | OtherState | FullState > > a > > deriving (Eq, Ord) > > > > When attempting to use, > > > > $ echo "- " | ./parser > > "- \n" > > empty ('-') > > $ echo "^ " | ./parser > > "^ \n" > > omitted ('^') > > $ echo "~ " | ./parser > > "~ \n" > > other ('~') > > [ all of this is as expected ] > > $ echo "1 " | ./parser > > "1 \n" > > [ computer twiddles it's thumbs here until I manually terminate it ... > > ] > > ^C^C > > $ > > > > Does anyone know what's happening and now to alleviate it? > > > > > > -- begin full code -- > > > > -- base > > import Control.Applicative > > import Data.Word > > > > -- Hackage > > import qualified Data.Text.Lazy as TL > > import qualified Data.Text.Lazy.IO as TLIO > > import Text.Parsec (parse) > > import Text.Parsec.Text.Lazy (Parser) > > import Text.Parser.Combinators > > import Text.Parser.Char > > > > data FieldState a = EmptyState | OmittedState | OtherState | FullState a > > deriving (Eq, Ord) > > > > instance Functor FieldState where > > fmap f (FullState a) = FullState (f a) > > fmap _ EmptyState = EmptyState > > fmap _ OmittedState = OmittedState > > fmap _ OtherState = OtherState > > > > instance Applicative FieldState where > > pure = FullState > > (FullState f) <*> (FullState x) = FullState (f x) > > _ <*> _ = EmptyState > > > > instance Monad FieldState where > > (FullState x) >>= k = k x > > EmptyState >>= _ = EmptyState > > OmittedState >>= _ = OmittedState > > OtherState >>= _ = OtherState > > > > (FullState _) >> k = k > > EmptyState >> _ = EmptyState > > OmittedState >> _ = OmittedState > > OtherState >> _ = OtherState > > > > return = FullState > > fail _ = EmptyState > > > > instance Show (FieldState x) where > > show (EmptyState) = "empty ('-')" > > show (OmittedState) = "omitted ('^')" > > show (OtherState) = "other ('~')" > > show x' = show x' > > > > data Counter = Counter Word64 deriving (Eq, Ord, Show) > > > > parseNum :: (Num a) => Parser a > > parseNum = do > > n <- rd <$> many digit > > return $ fromIntegral n > > where rd = read :: String -> Integer > > > > parseCounter :: Parser Counter > > parseCounter = Counter <$> parseNum > > > > parseFieldStateOff :: Parser Char > > parseFieldStateOff = char '-' > > > > parseFieldStateOmitted :: Parser Char > > parseFieldStateOmitted = char '^' > > > > parseFieldStateOther :: Parser Char > > parseFieldStateOther = char '~' > > > > parseFieldState :: Parser a -> Parser (FieldState a) > > parseFieldState p = (parseFieldStateOff >> return EmptyState) > > <|> (parseFieldStateOmitted >> return OmittedState) > > <|> (parseFieldStateOther >> return OtherState) > > <|> (p >>= return . FullState) > > > > main :: IO () > > main = do > > ls <- TLIO.getContents > > print ls > > mapM_ processLine (TL.lines ls) > > > > processLine :: TL.Text -> IO () > > processLine line = case (parse (parseFieldState parseCounter) "" line) of > > Left err -> print err > > Right xs -> print xs > > > > _______________________________________________ > > Beginners mailing list > > Beginners at haskell.org > > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > > -- -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 490 bytes Desc: not available URL: From shishir.srivastava at gmail.com Thu Mar 26 10:06:17 2015 From: shishir.srivastava at gmail.com (Shishir Srivastava) Date: Thu, 26 Mar 2015 10:06:17 +0000 Subject: [Haskell-beginners] Maybe and Just Message-ID: Hi, After reading and re-reading the haskell tutorials I don't happen to see a very convincing or appealing reason for having these data types. Can anyone please explain where Maybe and Just provide the sort of functionality that cannot be achieved in other languages which don't have these kind. Thanks, Shishir Srivastava -------------- next part -------------- An HTML attachment was scrubbed... URL: From shishir.srivastava at gmail.com Thu Mar 26 10:21:30 2015 From: shishir.srivastava at gmail.com (Shishir Srivastava) Date: Thu, 26 Mar 2015 10:21:30 +0000 Subject: [Haskell-beginners] Type Parameters and Type Variables Message-ID: What's the difference between the two.. ? Shishir Srivastava -------------- next part -------------- An HTML attachment was scrubbed... URL: From mdorman at ironicdesign.com Thu Mar 26 10:26:15 2015 From: mdorman at ironicdesign.com (Michael Alan Dorman) Date: Thu, 26 Mar 2015 06:26:15 -0400 Subject: [Haskell-beginners] Maybe and Just In-Reply-To: (Shishir Srivastava's message of "Thu, 26 Mar 2015 10:06:17 +0000") References: Message-ID: <87384soy0o.fsf@ironicdesign.com> Shishir Srivastava writes: > After reading and re-reading the haskell tutorials I don't happen to > see a very convincing or appealing reason for having these data > types. To be clear: Maybe is the data *type*. Just and Nothing are its data *constructors*. > Can anyone please explain where Maybe and Just provide the sort of > functionality that cannot be achieved in other languages which don't > have these kind. The functionality can be achieved in other languages, certainly. The question is whether the clarity and safety is also achieved. When I see (as a totally contrived example): fopen :: Maybe FileHandle I know that that function may not be able to return a FileHandle value all the time. The compiler will, in fact, nag me if I do not write the code that calls it in such a way that it acknowledges that possibility. When I see: FILE * fopen ( const char * filename, const char * mode ); It is not immediately clear whether that can fail. Sure, we can make that inference, based on what we know about filesystems, etc., but the compiler is never going to complain if I ignore the possibility. In my experience, programmers in many languages end up resorting to convention to try and work around these sorts of ambiguities. Large projects have strategies for naming functions that try to pass along information out of band, or languages have a pervasive culture of "lint" tools that try to use heuristics to make up for what the type system doesn't make simple. That said, I know that doing Maybe sorts of things in languages that don't have, say, pattern matching, or the idea of a "failure monad", gets to be a drag very quickly---manually unwrapping things is at best awkward, having to re-wrap them just to unwrap them again in a sequence of computations quickly leads one to believe "it's just not worth it"---or you resort to exception handling, which has its own challenges to do well. Mike. From maydwell at gmail.com Thu Mar 26 10:27:53 2015 From: maydwell at gmail.com (Lyndon Maydwell) Date: Thu, 26 Mar 2015 21:27:53 +1100 Subject: [Haskell-beginners] Maybe and Just In-Reply-To: References: Message-ID: Hi Shishir, Indeed, Maybe doesn't grant you additional operational functionality that other languages lack. Most use-cases of Maybe can be matched in nearly all mainstream languages through the use of NULL. Maybe illustrates a desired lack of functionality in cases where it is absent. For example, in Java: public static Integer myMethod(Integer a, Integer b) { // body} What do we know about this method from the signature? You would think it is a method that takes two integers and returns an integer, but really it could take NULLs too, and could possibly return a NULL. Here is the equivalent Haskell signature: myMethod :: Maybe Integer -> Maybe Integer -> IO (Maybe Integer) We can see that Maybe allows us to replicate the possibility of NULL values from other languages... But how is that special since other languages already have this built-in. Now look at the following Haskell signature: myMethod :: Integer -> Integer -> Integer Now what do we know about this? We know that it takes two Integers and returns an Integer. This is the power that comes from having Maybe as the canonical way to represent the possibility of missing values. On Thu, Mar 26, 2015 at 9:06 PM, Shishir Srivastava < shishir.srivastava at gmail.com> wrote: > Hi, > > After reading and re-reading the haskell tutorials I don't happen to see a > very convincing or appealing reason for having these data types. > > Can anyone please explain where Maybe and Just provide the sort of > functionality that cannot be achieved in other languages which don't have > these kind. > > Thanks, > Shishir Srivastava > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mwm at mired.org Thu Mar 26 10:28:40 2015 From: mwm at mired.org (Mike Meyer) Date: Thu, 26 Mar 2015 05:28:40 -0500 Subject: [Haskell-beginners] Maybe and Just In-Reply-To: References: Message-ID: On Thu, Mar 26, 2015 at 5:06 AM, Shishir Srivastava < shishir.srivastava at gmail.com> wrote: > Hi, > > After reading and re-reading the haskell tutorials I don't happen to see a > very convincing or appealing reason for having these data types. > > Can anyone please explain where Maybe and Just provide the sort of > functionality that cannot be achieved in other languages which don't have > these kind. > When a function fails to produce the return value, it can either return a distinguished value (a NULL pointer, or -1 to signal an error, or ...) or raise an exception. The latter is sufficiently clumsy that it's not uncommon to see languages with two versions of some functions: one that raises an exception, and one that returns a distinguished value. Haskell uses the Maybe type for the distinguished value, raising it to the type level. If I call a function that expects a value that is NOT the distinguished value (a valid pointer, or a valid array index, or ...) in languages without something like a Maybe type, I find out about it when my unit tests fail if I'm lucky, or I just get the wrong answer if I'm not. When I call a function that expects an X with a value of type Maybe X in Haskell, it's a type error at compile time. -------------- next part -------------- An HTML attachment was scrubbed... URL: From raabe at froglogic.com Thu Mar 26 10:34:58 2015 From: raabe at froglogic.com (Frerich Raabe) Date: Thu, 26 Mar 2015 11:34:58 +0100 Subject: [Haskell-beginners] Maybe and Just In-Reply-To: References: Message-ID: Hi, On 2015-03-26 11:06, Shishir Srivastava wrote: > After reading and re-reading the haskell tutorials I don't happen to see a > very convincing or appealing reason for having these data types. First of all, only one of them is a type (or a 'type constructor'): "Maybe". "Just" on the other hand is a "data constructor", i.e. "Just 'x'" will yield a value of type "Maybe Char". > Can anyone please explain where Maybe and Just provide the sort of > functionality that cannot be achieved in other languages which don't have > these kind. They don't provide anything which other languages cannot achieve. 'Maybe' values merely indicate that you *maybe* get a value. This is useful for functions which might not be able to yield a meaningful result. Consider a 'safeHead' function which works like 'head', returning the first element of a given list. What should it do for empty lists? Something like 'Maybe' is useful because it 1. Makes potential errors clearly visible in the type system: If a function returns a 'Maybe Char', you know that it possible won't yield a Char (but rather 'Nothing'). Raising an exception is totally opaque to the caller. 2. Clearly separates the values which might represent failures from those which don't. Contrast this with e.g. Java, where every object of every type can be null. If every value is potentially 'null', you either have to check using if() everywhere or use assertions. With 'Maybe', the null'ness can be asserted by the compiler. 3. Relieves other types from having an explicit 'Invalid' value. Consider: data Color = Red | Green | Blue | Invalid -- Parses a color string; yields 'Invalid' if the string is malformed parseColor :: String -> Color parseColor = undefind With a setup like this, *every* code dealing with 'Color' values will have to be able to handle 'Invalid' colors. It ripples through the system. OTOH, something like data Color = Red | Green | Blue -- Parses a color string; yields 'Nothing' if the string is malformed parseColor :: String -> Maybe Color parseColor = undefined Clearly separates the valid colors, such that only the caller of 'parseColor' only has to check for 'Just x' values - and if it got one, it can pass the 'x' value to other code. For what it's worth, other languages have similiar concepts. For instance, C++ programmers can use 'boost::optional' (which, alas, didn't make it into C++14). -- Frerich Raabe - raabe at froglogic.com www.froglogic.com - Multi-Platform GUI Testing From sumit.sahrawat.apm13 at iitbhu.ac.in Thu Mar 26 10:48:52 2015 From: sumit.sahrawat.apm13 at iitbhu.ac.in (Sumit Sahrawat, Maths & Computing, IIT (BHU)) Date: Thu, 26 Mar 2015 16:18:52 +0530 Subject: [Haskell-beginners] Type Parameters and Type Variables In-Reply-To: References: Message-ID: When type variables are passed to a Type Constructor, they become type parameters. Just like when variables are passed to functions, they become parameters. Operationally, both are equivalent. On 26 March 2015 at 15:51, Shishir Srivastava wrote: > What's the difference between the two.. ? > > Shishir Srivastava > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -- Regards Sumit Sahrawat -------------- next part -------------- An HTML attachment was scrubbed... URL: From joel.neely at gmail.com Thu Mar 26 11:54:29 2015 From: joel.neely at gmail.com (Joel Neely) Date: Thu, 26 Mar 2015 06:54:29 -0500 Subject: [Haskell-beginners] Empty list In-Reply-To: References: Message-ID: Given the distinction between lists and sets, you might also consider Prelude Data.Set Data.List> [] `isInfixOf` [1,2,3] True Prelude Data.Set Data.List> (fromList []) `isSubsetOf` (fromList [1,2,3]) True Of course `isInfixOf` is in general more restrictive than `isSubsetOf`, in the sense that the infix relationship depends on ordering, which the subset relationship does not. Hope that helps, -jn- On Wed, Mar 25, 2015 at 8:55 AM, Shishir Srivastava < shishir.srivastava at gmail.com> wrote: > Hi, > > Can someone please explain why this results in error - > > [] `elem` [1,2,3] > > Shouldn't the empty set by definition be the element of all sets including > a non-empty set ? > > I am assuming 'Lists' are different from 'Sets' in Haskell, if yes, is > there a separate module for dealing/working with sets ? > > Thanks, > Shishir Srivastava > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -- Beauty of style and harmony and grace and good rhythm depend on simplicity. - Plato -------------- next part -------------- An HTML attachment was scrubbed... URL: From joel.neely at gmail.com Thu Mar 26 12:37:28 2015 From: joel.neely at gmail.com (Joel Neely) Date: Thu, 26 Mar 2015 07:37:28 -0500 Subject: [Haskell-beginners] Maybe and Just In-Reply-To: References: Message-ID: Hi, Shishir, As a recovering complexity addict (i.e. Java programmer ;-), I'd put it this way. There are many methods (on many types) that can either succeed and return a meaningful value, or be unable to fulfill the intent of the caller's request. Example include indexOf on String, get on Map, and read on a Reader. Every time such a partial function scenario occurs, the author must decide what to do if the intent can't be fulfilled. That freedom of choice has led to a proliferation of techniques. - indexOf returns -1, which is a valid int, but not a valid position within a string. - get returns null, which is the only value common to all reference types that means 'I have nothing'. Of course, that also prevents one from storing null in a Map and simply retrieving it. Worse, if that result is passed along elsewhere, one can eventually receive a NullPointerException occurring in a completely different part of the code. - And, *horrors!*, read responds in a totally different way, by forcing the caller to "jump" somewhere. Maybe provides a general, reusable solution to all such cases. - It allows one to "stretch" any type to include an extra "out of band" value. - The type declaration clearly (uniformly) notifies anyone else that the function may have to return "lack of result". - The type system prevents a caller from simply assuming that a result is present, and then accidentally propagating failure. - Because Maybe is an instance of Functor, one can use map to safely apply a function (or do nothing gracefully) without littering the calling code with if-statements. - etc. I don't think of Maybe as enabling a *computation* that is impossible otherwise, but I do regard it as providing a *consistency and simplicity* that is otherwise not present. Hope this helps, Joel On Thu, Mar 26, 2015 at 5:06 AM, Shishir Srivastava < shishir.srivastava at gmail.com> wrote: > Hi, > > After reading and re-reading the haskell tutorials I don't happen to see a > very convincing or appealing reason for having these data types. > > Can anyone please explain where Maybe and Just provide the sort of > functionality that cannot be achieved in other languages which don't have > these kind. > > Thanks, > Shishir Srivastava > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -- Beauty of style and harmony and grace and good rhythm depend on simplicity. - Plato -------------- next part -------------- An HTML attachment was scrubbed... URL: From d12frosted at icloud.com Thu Mar 26 13:17:37 2015 From: d12frosted at icloud.com (Boris) Date: Thu, 26 Mar 2015 15:17:37 +0200 Subject: [Haskell-beginners] Monoids and Groups In-Reply-To: References: Message-ID: Hi, While they have similarities, they are not the same. Semigroup (S,*) is a set S with associative binary operation *. Monoid is a semigroup that has identity element i such that i * a = a and a * i = a. And group is a monoid in which every element of set has it?s own inverse: a * b = i and b * a = i where b is an inverse of a. Let?s look at the definition of Monoid in haskell. class Monoid a where mempty :: a -- ^ Identity of 'mappend' mappend :: a -> a -> a -- ^ An associative operation mconcat :: [a] -> a -- ^ Fold a list using the monoid. -- For most types, the default definition for 'mconcat' will be -- used, but the function is included in the class definition so -- that an optimized version can be provided for specific types. mconcat = foldr mappend mempty So we have a set of a, associative binary operation mappend and identity element mempty. The only difference between Monoid a in haskell and monoid in algebra is that Monoid in haskell has mconcat function in it?s definition. But you can ignore it. I hope it helps. Cheers, d12frosted On March 25, 2015 at 16:03:14, Shishir Srivastava (shishir.srivastava at gmail.com) wrote: Hi,? Reading about Monoids it seems they derive a lot on the algebraic structures of 'Groups' ?? Is it then correct to assume that Monoids can be used to represent 'Groups' ? If not are there any standard haskell libraries which represent algebraic structures such as 'Groups' , 'Fields' etc. Thanks, Shishir Srivastava _______________________________________________ Beginners mailing list Beginners at haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: From mwm at mired.org Thu Mar 26 13:36:30 2015 From: mwm at mired.org (Mike Meyer) Date: Thu, 26 Mar 2015 08:36:30 -0500 Subject: [Haskell-beginners] Something like pydoc? Message-ID: Python had the "pydoc" command, which would could be used to print a module's docstings from the command line, and provided the "help" function in the REPL. Clojure has "doc" in the REPL, at least if you told it where the sources were. I can't seem to find anything like that for Haskell - either at the command line or in ghci. Does such exist? Is such possible? Thanks, From toad3k at gmail.com Thu Mar 26 13:44:19 2015 From: toad3k at gmail.com (David McBride) Date: Thu, 26 Mar 2015 09:44:19 -0400 Subject: [Haskell-beginners] Something like pydoc? In-Reply-To: References: Message-ID: There is a hoogle command: https://hackage.haskell.org/package/hoogle. I don't use it, but I imagine you would have to set documention: True in cabal.config, so you get documentation for any packages you have, and then either use your browser, or put an alias in your .ghci to query it in your repl, or just use the executable. On Thu, Mar 26, 2015 at 9:36 AM, Mike Meyer wrote: > Python had the "pydoc" command, which would could be used to print a > module's docstings from the command line, and provided the "help" function > in the REPL. Clojure has "doc" in the REPL, at least if you told it where > the sources were. > > I can't seem to find anything like that for Haskell - either at the > command line or in ghci. Does such exist? Is such possible? > > Thanks, > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mwm at mired.org Thu Mar 26 14:27:13 2015 From: mwm at mired.org (Mike Meyer) Date: Thu, 26 Mar 2015 09:27:13 -0500 Subject: [Haskell-beginners] Something like pydoc? In-Reply-To: References: Message-ID: On Thu, Mar 26, 2015 at 8:44 AM, David McBride wrote: > There is a hoogle command: https://hackage.haskell.org/package/hoogle. > > I don't use it, but I imagine you would have to set documention: True in > cabal.config, so you get documentation for any packages you have, and then > either use your browser, or put an alias in your .ghci to query it in your > repl, or just use the executable. > The appropriate entries for .ghci are: :def hoogle \x -> return $ ":!hoogle \"" ++ x ++ "\"" :def doc \x -> return $ ":!hoogle --info \"" ++ x ++ "\"" That's actually close enough. However, the python & clojure commands use the current search path, not a database build from the online docs. I suspect this means I want a cabal command. -------------- next part -------------- An HTML attachment was scrubbed... URL: From shishir.srivastava at gmail.com Thu Mar 26 15:26:40 2015 From: shishir.srivastava at gmail.com (Shishir Srivastava) Date: Thu, 26 Mar 2015 15:26:40 +0000 Subject: [Haskell-beginners] Maybe and Just In-Reply-To: <87384soy0o.fsf@ironicdesign.com> References: <87384soy0o.fsf@ironicdesign.com> Message-ID: ok..but what's with using the keyword 'Just' ? why cannot 'Maybe' be defined like this data Maybe a = a | Nothing what's the point in having 'Just' keyword ? Shishir On Thu, Mar 26, 2015 at 10:26 AM, Michael Alan Dorman < mdorman at ironicdesign.com> wrote: > Shishir Srivastava writes: > > After reading and re-reading the haskell tutorials I don't happen to > > see a very convincing or appealing reason for having these data > > types. > > To be clear: Maybe is the data *type*. Just and Nothing are its data > *constructors*. > > > Can anyone please explain where Maybe and Just provide the sort of > > functionality that cannot be achieved in other languages which don't > > have these kind. > > The functionality can be achieved in other languages, certainly. The > question is whether the clarity and safety is also achieved. > > When I see (as a totally contrived example): > > fopen :: Maybe FileHandle > > I know that that function may not be able to return a FileHandle value > all the time. The compiler will, in fact, nag me if I do not write the > code that calls it in such a way that it acknowledges that possibility. > > When I see: > > FILE * fopen ( const char * filename, const char * mode ); > > It is not immediately clear whether that can fail. Sure, we can make > that inference, based on what we know about filesystems, etc., but the > compiler is never going to complain if I ignore the possibility. > > In my experience, programmers in many languages end up resorting to > convention to try and work around these sorts of ambiguities. Large > projects have strategies for naming functions that try to pass along > information out of band, or languages have a pervasive culture of "lint" > tools that try to use heuristics to make up for what the type system > doesn't make simple. > > That said, I know that doing Maybe sorts of things in languages that > don't have, say, pattern matching, or the idea of a "failure monad", > gets to be a drag very quickly---manually unwrapping things is at best > awkward, having to re-wrap them just to unwrap them again in a sequence > of computations quickly leads one to believe "it's just not worth > it"---or you resort to exception handling, which has its own challenges > to do well. > > Mike. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From allbery.b at gmail.com Thu Mar 26 15:46:45 2015 From: allbery.b at gmail.com (Brandon Allbery) Date: Thu, 26 Mar 2015 11:46:45 -0400 Subject: [Haskell-beginners] Maybe and Just In-Reply-To: References: <87384soy0o.fsf@ironicdesign.com> Message-ID: On Thu, Mar 26, 2015 at 11:26 AM, Shishir Srivastava < shishir.srivastava at gmail.com> wrote: > ok..but what's with using the keyword 'Just' ? why cannot 'Maybe' be > defined like this > > data Maybe a = a | Nothing > Because type inference won't work if you don't have a distinction between an a and a Maybe a. Also, you end up back where you started --- there's a distinguished (non)value that appears to be a value of the type, which leaves you no better off than with C's NULL or Perl's undef, losing the type safety of "this can't fail" vs. "this may fail and you must deal with the failure somehow". -- brandon s allbery kf8nh sine nomine associates allbery.b at gmail.com ballbery at sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From corentin.dupont at gmail.com Thu Mar 26 15:48:31 2015 From: corentin.dupont at gmail.com (Corentin Dupont) Date: Thu, 26 Mar 2015 16:48:31 +0100 Subject: [Haskell-beginners] Maybe and Just In-Reply-To: References: <87384soy0o.fsf@ironicdesign.com> Message-ID: Hi Shishir, I think that's a legitimate question. By writing data Maybe a = a | Nothing you are saying that the type of the left hand side of the = is the same that right hand side (you are defining a type basically). Also you can only sum things of the same type. So you are saying: type "Maybe a" = type "a" Which is wrong. That's why "a" should be wrapped into something: type of "Just a" is indeed "Maybe a". "Just" is a type constructor: Just :: a -> Maybe a It allows you to build the Maybe. Said that, "Just" is a vocabulary choice. Personally I prefer the name choices of OCaml, Rust, Scala etc.: Option a = None | Some a On Thu, Mar 26, 2015 at 4:26 PM, Shishir Srivastava < shishir.srivastava at gmail.com> wrote: > ok..but what's with using the keyword 'Just' ? why cannot 'Maybe' be > defined like this > > data Maybe a = a | Nothing > > what's the point in having 'Just' keyword ? > > Shishir > > > On Thu, Mar 26, 2015 at 10:26 AM, Michael Alan Dorman < > mdorman at ironicdesign.com> wrote: > >> Shishir Srivastava writes: >> > After reading and re-reading the haskell tutorials I don't happen to >> > see a very convincing or appealing reason for having these data >> > types. >> >> To be clear: Maybe is the data *type*. Just and Nothing are its data >> *constructors*. >> >> > Can anyone please explain where Maybe and Just provide the sort of >> > functionality that cannot be achieved in other languages which don't >> > have these kind. >> >> The functionality can be achieved in other languages, certainly. The >> question is whether the clarity and safety is also achieved. >> >> When I see (as a totally contrived example): >> >> fopen :: Maybe FileHandle >> >> I know that that function may not be able to return a FileHandle value >> all the time. The compiler will, in fact, nag me if I do not write the >> code that calls it in such a way that it acknowledges that possibility. >> >> When I see: >> >> FILE * fopen ( const char * filename, const char * mode ); >> >> It is not immediately clear whether that can fail. Sure, we can make >> that inference, based on what we know about filesystems, etc., but the >> compiler is never going to complain if I ignore the possibility. >> >> In my experience, programmers in many languages end up resorting to >> convention to try and work around these sorts of ambiguities. Large >> projects have strategies for naming functions that try to pass along >> information out of band, or languages have a pervasive culture of "lint" >> tools that try to use heuristics to make up for what the type system >> doesn't make simple. >> >> That said, I know that doing Maybe sorts of things in languages that >> don't have, say, pattern matching, or the idea of a "failure monad", >> gets to be a drag very quickly---manually unwrapping things is at best >> awkward, having to re-wrap them just to unwrap them again in a sequence >> of computations quickly leads one to believe "it's just not worth >> it"---or you resort to exception handling, which has its own challenges >> to do well. >> >> Mike. >> > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From objitsu at gmail.com Thu Mar 26 16:25:28 2015 From: objitsu at gmail.com (emacstheviking) Date: Thu, 26 Mar 2015 16:25:28 +0000 Subject: [Haskell-beginners] Maybe and Just In-Reply-To: <87384soy0o.fsf@ironicdesign.com> References: <87384soy0o.fsf@ironicdesign.com> Message-ID: For what its worth I wrote this a while back, a hopeless attempt to do something "monad like" in PHP but reading it again..... well, it's no wonder I like Haskell more than I like having to use PHP! http://objitsu.blogspot.co.uk/2013/01/php-and-maybe-miserable-monads.html On 26 March 2015 at 10:26, Michael Alan Dorman wrote: > Shishir Srivastava writes: > > After reading and re-reading the haskell tutorials I don't happen to > > see a very convincing or appealing reason for having these data > > types. > > To be clear: Maybe is the data *type*. Just and Nothing are its data > *constructors*. > > > Can anyone please explain where Maybe and Just provide the sort of > > functionality that cannot be achieved in other languages which don't > > have these kind. > > The functionality can be achieved in other languages, certainly. The > question is whether the clarity and safety is also achieved. > > When I see (as a totally contrived example): > > fopen :: Maybe FileHandle > > I know that that function may not be able to return a FileHandle value > all the time. The compiler will, in fact, nag me if I do not write the > code that calls it in such a way that it acknowledges that possibility. > > When I see: > > FILE * fopen ( const char * filename, const char * mode ); > > It is not immediately clear whether that can fail. Sure, we can make > that inference, based on what we know about filesystems, etc., but the > compiler is never going to complain if I ignore the possibility. > > In my experience, programmers in many languages end up resorting to > convention to try and work around these sorts of ambiguities. Large > projects have strategies for naming functions that try to pass along > information out of band, or languages have a pervasive culture of "lint" > tools that try to use heuristics to make up for what the type system > doesn't make simple. > > That said, I know that doing Maybe sorts of things in languages that > don't have, say, pattern matching, or the idea of a "failure monad", > gets to be a drag very quickly---manually unwrapping things is at best > awkward, having to re-wrap them just to unwrap them again in a sequence > of computations quickly leads one to believe "it's just not worth > it"---or you resort to exception handling, which has its own challenges > to do well. > > Mike. > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From corentin.dupont at gmail.com Thu Mar 26 17:31:34 2015 From: corentin.dupont at gmail.com (Corentin Dupont) Date: Thu, 26 Mar 2015 18:31:34 +0100 Subject: [Haskell-beginners] Maybe and Just In-Reply-To: References: <87384soy0o.fsf@ironicdesign.com> Message-ID: Not really, when you define the type "Maybe a": data Maybe a = Just a | Nothing Haskell is creating automatically two functions for you: Just :: a -> Maybe a Nothing :: Maybe a In the first case, you can think of "Just" and "Nothing" as a sort of tag identifying which element of the sum you have. It the second case it's a function, with the same name. A more informed person than me could say if they are indeed separated of if they are the same thing in GHC... On Thu, Mar 26, 2015 at 5:34 PM, Shishir Srivastava < shishir.srivastava at gmail.com> wrote: > isn't that then cyclic dependency between 'Maybe' and 'Just' ...where the > first one is defined in terms of second and vice-versa...? > > Shishir > > > On Thu, Mar 26, 2015 at 3:48 PM, Corentin Dupont < > corentin.dupont at gmail.com> wrote: > >> Hi Shishir, >> I think that's a legitimate question. >> >> By writing >> >> data Maybe a = a | Nothing >> >> you are saying that the type of the left hand side of the = is the same >> that right hand side (you are defining a type basically). >> Also you can only sum things of the same type. >> So you are saying: >> type "Maybe a" = type "a" >> Which is wrong. >> That's why "a" should be wrapped into something: >> type of "Just a" is indeed "Maybe a". >> >> "Just" is a type constructor: >> Just :: a -> Maybe a >> It allows you to build the Maybe. >> >> Said that, "Just" is a vocabulary choice. >> Personally I prefer the name choices of OCaml, Rust, Scala etc.: Option >> a = None | Some a >> >> >> >> On Thu, Mar 26, 2015 at 4:26 PM, Shishir Srivastava < >> shishir.srivastava at gmail.com> wrote: >> >>> ok..but what's with using the keyword 'Just' ? why cannot 'Maybe' be >>> defined like this >>> >>> data Maybe a = a | Nothing >>> >>> what's the point in having 'Just' keyword ? >>> >>> Shishir >>> >>> >>> On Thu, Mar 26, 2015 at 10:26 AM, Michael Alan Dorman < >>> mdorman at ironicdesign.com> wrote: >>> >>>> Shishir Srivastava writes: >>>> > After reading and re-reading the haskell tutorials I don't happen to >>>> > see a very convincing or appealing reason for having these data >>>> > types. >>>> >>>> To be clear: Maybe is the data *type*. Just and Nothing are its data >>>> *constructors*. >>>> >>>> > Can anyone please explain where Maybe and Just provide the sort of >>>> > functionality that cannot be achieved in other languages which don't >>>> > have these kind. >>>> >>>> The functionality can be achieved in other languages, certainly. The >>>> question is whether the clarity and safety is also achieved. >>>> >>>> When I see (as a totally contrived example): >>>> >>>> fopen :: Maybe FileHandle >>>> >>>> I know that that function may not be able to return a FileHandle value >>>> all the time. The compiler will, in fact, nag me if I do not write the >>>> code that calls it in such a way that it acknowledges that possibility. >>>> >>>> When I see: >>>> >>>> FILE * fopen ( const char * filename, const char * mode ); >>>> >>>> It is not immediately clear whether that can fail. Sure, we can make >>>> that inference, based on what we know about filesystems, etc., but the >>>> compiler is never going to complain if I ignore the possibility. >>>> >>>> In my experience, programmers in many languages end up resorting to >>>> convention to try and work around these sorts of ambiguities. Large >>>> projects have strategies for naming functions that try to pass along >>>> information out of band, or languages have a pervasive culture of "lint" >>>> tools that try to use heuristics to make up for what the type system >>>> doesn't make simple. >>>> >>>> That said, I know that doing Maybe sorts of things in languages that >>>> don't have, say, pattern matching, or the idea of a "failure monad", >>>> gets to be a drag very quickly---manually unwrapping things is at best >>>> awkward, having to re-wrap them just to unwrap them again in a sequence >>>> of computations quickly leads one to believe "it's just not worth >>>> it"---or you resort to exception handling, which has its own challenges >>>> to do well. >>>> >>>> Mike. >>>> >>> >>> >>> _______________________________________________ >>> Beginners mailing list >>> Beginners at haskell.org >>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>> >>> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From martin.drautzburg at web.de Thu Mar 26 20:18:37 2015 From: martin.drautzburg at web.de (martin) Date: Thu, 26 Mar 2015 21:18:37 +0100 Subject: [Haskell-beginners] ap = liftM2 id Message-ID: <5514699D.6070209@web.de> Hello all, can someone explain ap = liftM2 id to me? liftM2 wants a binary funcation liftM2 :: (Monad m) => (a1 -> a2 -> r) -> m a1 -> m a2 -> m r but id is unary. How does this work? From andres at well-typed.com Thu Mar 26 20:33:46 2015 From: andres at well-typed.com (=?UTF-8?Q?Andres_L=C3=B6h?=) Date: Thu, 26 Mar 2015 21:33:46 +0100 Subject: [Haskell-beginners] ap = liftM2 id In-Reply-To: <5514699D.6070209@web.de> References: <5514699D.6070209@web.de> Message-ID: There's no such thing as a fixed arity of a function in Haskell. The type of id is > id :: a -> a If you instantiate "a" with "b -> c", then it becomes > id :: (b -> c) -> b -> c and it suddenly takes two arguments. In fact, it then behaves like function application. Try > id not True or > not `id` True and you'll see that it works as if you had used function application or $ instead. So ap lifts function application, and if it helps, you can think of it as instead being defined as > ap = liftM2 ($) Cheers, Andres On Thu, Mar 26, 2015 at 9:18 PM, martin wrote: > Hello all, > > can someone explain > > ap = liftM2 id > > to me? liftM2 wants a binary funcation > > liftM2 :: (Monad m) => (a1 -> a2 -> r) -> m a1 -> m a2 -> m r > > but id is unary. How does this work? > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -- Andres L?h, Haskell Consultant Well-Typed LLP, http://www.well-typed.com Registered in England & Wales, OC335890 250 Ice Wharf, 17 New Wharf Road, London N1 9RF, England From martin.drautzburg at web.de Thu Mar 26 21:04:47 2015 From: martin.drautzburg at web.de (martin) Date: Thu, 26 Mar 2015 22:04:47 +0100 Subject: [Haskell-beginners] Maybe and Just In-Reply-To: References: Message-ID: <5514746F.6060702@web.de> Am 03/26/2015 um 11:06 AM schrieb Shishir Srivastava: > Hi, > > After reading and re-reading the haskell tutorials I don't happen to see a very convincing or appealing reason for > having these data types. > > Can anyone please explain where Maybe and Just provide the sort of functionality that cannot be achieved in other > languages which don't have these kind. My intuition goes like that: "Maybe" is like "nullable" (which doesn't really exist, but you sure can imagine what it means). In many programming languages a variable of any type can contain "null", i.e. every type is nullable. This means that any function accepting one of these types as a parameter must be prepared to see a null. You end up with many checks like if (x==null) {return null;} Not so in haskell. An Int is really an Int and Ints cannot be null. Functions accepting Ints don't have to check for null. But you can beef up any datatype to be nullable. You can create a TYPE "nullable Int" which would be called "Maybe Int" in Haskell. Just like "nullable" alone, Maybe itself is not a type, but an up-beefer of another type. There are no values of type Maybe, but only of Maybe Int, Maybe String etc. In that respect maybe is like "List". There are no values of type "List", but only of List of Int, List of String. List is an up-beefer too (written as [] in Haskell) Obviously there needs to be a distinct VALUE for "null". In Haskell this value is called "Nothing". For the non-null VALUES you could think about writing them verbatim, like "42". But from just looking at 42, you couldn't tell what type it is. It could be an Int or a Maybe Int. This problem is somewhat akin to writing 42.0 when you want to make sure it is a float (in imperative languages), or 42L to indicate it is a long. So in the same vein, you distinguish an Int (42) from a Maybe Int (Just 42). Just 42 is a value of type Maybe Int, which just (sic!) happens not to be null, but it is still not a plain Int, but a Maybe Int. Like 42.0 is a float which happens not to have any digits after the decimal point but also is not a plain Int but a float. From martin.drautzburg at web.de Thu Mar 26 21:48:37 2015 From: martin.drautzburg at web.de (martin) Date: Thu, 26 Mar 2015 22:48:37 +0100 Subject: [Haskell-beginners] ap = liftM2 id In-Reply-To: References: <5514699D.6070209@web.de> Message-ID: <55147EB5.2010002@web.de> Am 03/26/2015 um 09:33 PM schrieb Andres L?h: I'll have to think about this. But other than that I am laughing my ass off after reading your paper about "Konjunktiv III". I can hardly type. > There's no such thing as a fixed arity of a function in Haskell. The > type of id is > >> id :: a -> a > > If you instantiate "a" with "b -> c", then it becomes > >> id :: (b -> c) -> b -> c > > and it suddenly takes two arguments. In fact, it then behaves like > function application. Try > >> id not True > > or > >> not `id` True > > and you'll see that it works as if you had used function application > or $ instead. So ap lifts function application, and if it helps, you > can think of it as instead being defined as > >> ap = liftM2 ($) > > Cheers, > Andres > > > On Thu, Mar 26, 2015 at 9:18 PM, martin wrote: >> Hello all, >> >> can someone explain >> >> ap = liftM2 id >> >> to me? liftM2 wants a binary funcation >> >> liftM2 :: (Monad m) => (a1 -> a2 -> r) -> m a1 -> m a2 -> m r >> >> but id is unary. How does this work? >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > > From andres.loeh at gmail.com Thu Mar 26 22:19:20 2015 From: andres.loeh at gmail.com (=?UTF-8?Q?Andres_L=C3=B6h?=) Date: Thu, 26 Mar 2015 23:19:20 +0100 Subject: [Haskell-beginners] ap = liftM2 id In-Reply-To: <55147EB5.2010002@web.de> References: <5514699D.6070209@web.de> <55147EB5.2010002@web.de> Message-ID: > I'll have to think about this. But other than that I am laughing my ass off after reading your paper about "Konjunktiv > III". I can hardly type. Oh, that was written a long, long time ago. Glad you like it :) Cheers, Andres From greg at grahamtx.net Thu Mar 26 23:05:56 2015 From: greg at grahamtx.net (Greg Graham) Date: Thu, 26 Mar 2015 18:05:56 -0500 Subject: [Haskell-beginners] Maybe and Just In-Reply-To: <5514746F.6060702@web.de> References: <5514746F.6060702@web.de> Message-ID: On Thu, Mar 26, 2015 at 4:04 PM, martin wrote: > Am 03/26/2015 um 11:06 AM schrieb Shishir Srivastava: >> Hi, >> >> After reading and re-reading the haskell tutorials I don't happen to see a very convincing or appealing reason for >> having these data types. >> >> Can anyone please explain where Maybe and Just provide the sort of functionality that cannot be achieved in other >> languages which don't have these kind. I'm reading the little book, _Maybe Haskell_ [1], and I'm finding it very helpful on this topic. The whole Maybe paradigm is one of the reasons I decided to learn Haskell. I had previously started learning Go, and although I was initially attracted by its simplicity, I came to dislike how it used return values to indicate errors. Go typically returns a pair of values from operations that can fail. One value is the normal return value, and the other is an error code. At first look, I thought it was similar to Haskell's Maybe. However, after doing a little Go programming, I realized there's a big difference. The error codes in Go can be ignored, sometimes accidentally, but you can't ignore Haskell's Maybe. Sure, it's possible to respond poorly, but you do have to respond, all because (Just 42) is not the same thing as (42). 1: https://robots.thoughtbot.com/maybe-haskell-our-newest-book From rein.henrichs at gmail.com Fri Mar 27 00:34:46 2015 From: rein.henrichs at gmail.com (Rein Henrichs) Date: Thu, 26 Mar 2015 17:34:46 -0700 Subject: [Haskell-beginners] ap = liftM2 id In-Reply-To: References: <5514699D.6070209@web.de> <55147EB5.2010002@web.de> Message-ID: Following up on Andres's explanation, we have ap f x = liftM2 id mf ma -- definition of ap = do { f <- mf; a <- ma; return (id f x) } -- definition of liftM2 = do { f <- mf; a <- ma; return (f x) } -- definition of id, f x y = (f x) y We can see that id applied to f gives f which is then applied to a. -------------- next part -------------- An HTML attachment was scrubbed... URL: From shishir.srivastava at gmail.com Fri Mar 27 09:44:22 2015 From: shishir.srivastava at gmail.com (Shishir Srivastava) Date: Fri, 27 Mar 2015 09:44:22 +0000 Subject: [Haskell-beginners] Maybe and Just In-Reply-To: References: <87384soy0o.fsf@ironicdesign.com> Message-ID: Sorry, but I still have some grudges so to say with the way 'Maybe' is defined. By definition '*Maybe*' takes a type parameter which I will denote here as ' *tp*' for the sake of clarity like below - data Maybe tp = Just tp | Nothing Therefore '*tp*' is not representing a value perse such as '3' or 'XYZ' etc but a data type such as '*Int*', '*Char*' etc. But when we have to create a data type of '*Maybe*' we write '*Just 3*' and not '*Just Int*' or '*Just Char*' which is how it's defined in the definition (i.e. '*Just tp*' ) . It is this discrepancy in definition and the actual value creation which is slightly troubling me. Thanks, Shishir Shishir Srivastava +44 (0) 750 127 5019 On Thu, Mar 26, 2015 at 5:31 PM, Corentin Dupont wrote: > Not really, when you define the type "Maybe a": > > data Maybe a = Just a | Nothing > > Haskell is creating automatically two functions for you: > > Just :: a -> Maybe a > Nothing :: Maybe a > > In the first case, you can think of "Just" and "Nothing" as a sort of tag > identifying which element of the sum you have. > It the second case it's a function, with the same name. > A more informed person than me could say if they are indeed separated of > if they are the same thing in GHC... > > > On Thu, Mar 26, 2015 at 5:34 PM, Shishir Srivastava < > shishir.srivastava at gmail.com> wrote: > >> isn't that then cyclic dependency between 'Maybe' and 'Just' ...where the >> first one is defined in terms of second and vice-versa...? >> >> Shishir >> >> >> On Thu, Mar 26, 2015 at 3:48 PM, Corentin Dupont < >> corentin.dupont at gmail.com> wrote: >> >>> Hi Shishir, >>> I think that's a legitimate question. >>> >>> By writing >>> >>> data Maybe a = a | Nothing >>> >>> you are saying that the type of the left hand side of the = is the same >>> that right hand side (you are defining a type basically). >>> Also you can only sum things of the same type. >>> So you are saying: >>> type "Maybe a" = type "a" >>> Which is wrong. >>> That's why "a" should be wrapped into something: >>> type of "Just a" is indeed "Maybe a". >>> >>> "Just" is a type constructor: >>> Just :: a -> Maybe a >>> It allows you to build the Maybe. >>> >>> Said that, "Just" is a vocabulary choice. >>> Personally I prefer the name choices of OCaml, Rust, Scala etc.: Option >>> a = None | Some a >>> >>> >>> >>> On Thu, Mar 26, 2015 at 4:26 PM, Shishir Srivastava < >>> shishir.srivastava at gmail.com> wrote: >>> >>>> ok..but what's with using the keyword 'Just' ? why cannot 'Maybe' be >>>> defined like this >>>> >>>> data Maybe a = a | Nothing >>>> >>>> what's the point in having 'Just' keyword ? >>>> >>>> Shishir >>>> >>>> >>>> On Thu, Mar 26, 2015 at 10:26 AM, Michael Alan Dorman < >>>> mdorman at ironicdesign.com> wrote: >>>> >>>>> Shishir Srivastava writes: >>>>> > After reading and re-reading the haskell tutorials I don't happen to >>>>> > see a very convincing or appealing reason for having these data >>>>> > types. >>>>> >>>>> To be clear: Maybe is the data *type*. Just and Nothing are its data >>>>> *constructors*. >>>>> >>>>> > Can anyone please explain where Maybe and Just provide the sort of >>>>> > functionality that cannot be achieved in other languages which don't >>>>> > have these kind. >>>>> >>>>> The functionality can be achieved in other languages, certainly. The >>>>> question is whether the clarity and safety is also achieved. >>>>> >>>>> When I see (as a totally contrived example): >>>>> >>>>> fopen :: Maybe FileHandle >>>>> >>>>> I know that that function may not be able to return a FileHandle value >>>>> all the time. The compiler will, in fact, nag me if I do not write the >>>>> code that calls it in such a way that it acknowledges that possibility. >>>>> >>>>> When I see: >>>>> >>>>> FILE * fopen ( const char * filename, const char * mode ); >>>>> >>>>> It is not immediately clear whether that can fail. Sure, we can make >>>>> that inference, based on what we know about filesystems, etc., but the >>>>> compiler is never going to complain if I ignore the possibility. >>>>> >>>>> In my experience, programmers in many languages end up resorting to >>>>> convention to try and work around these sorts of ambiguities. Large >>>>> projects have strategies for naming functions that try to pass along >>>>> information out of band, or languages have a pervasive culture of >>>>> "lint" >>>>> tools that try to use heuristics to make up for what the type system >>>>> doesn't make simple. >>>>> >>>>> That said, I know that doing Maybe sorts of things in languages that >>>>> don't have, say, pattern matching, or the idea of a "failure monad", >>>>> gets to be a drag very quickly---manually unwrapping things is at best >>>>> awkward, having to re-wrap them just to unwrap them again in a sequence >>>>> of computations quickly leads one to believe "it's just not worth >>>>> it"---or you resort to exception handling, which has its own challenges >>>>> to do well. >>>>> >>>>> Mike. >>>>> >>>> >>>> >>>> _______________________________________________ >>>> Beginners mailing list >>>> Beginners at haskell.org >>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>> >>>> >>> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From corentin.dupont at gmail.com Fri Mar 27 09:53:23 2015 From: corentin.dupont at gmail.com (Corentin Dupont) Date: Fri, 27 Mar 2015 10:53:23 +0100 Subject: [Haskell-beginners] Maybe and Just In-Reply-To: References: <87384soy0o.fsf@ironicdesign.com> Message-ID: You're right, "Just" is used at two different levels, it's just that it have the same name is both cases. One is at type level, the other at value level. Since this is two separated levels, there is no risk of confusion and having the same name is fine. To be clear, you can write: data Maybe tp = Just Int | Nothing Then use it as: my_value = Just 3 On Fri, Mar 27, 2015 at 10:44 AM, Shishir Srivastava < shishir.srivastava at gmail.com> wrote: > Sorry, but I still have some grudges so to say with the way 'Maybe' is > defined. > > By definition '*Maybe*' takes a type parameter which I will denote here > as '*tp*' for the sake of clarity like below - > > data Maybe tp = Just tp | Nothing > > Therefore '*tp*' is not representing a value perse such as '3' or 'XYZ' > etc but a data type such as '*Int*', '*Char*' etc. > > But when we have to create a data type of '*Maybe*' we write '*Just 3*' > and not '*Just Int*' or '*Just Char*' which is how it's defined in the > definition (i.e. '*Just tp*' ) . > > It is this discrepancy in definition and the actual value creation which > is slightly troubling me. > > Thanks, > Shishir > > Shishir Srivastava > +44 (0) 750 127 5019 > > > On Thu, Mar 26, 2015 at 5:31 PM, Corentin Dupont < > corentin.dupont at gmail.com> wrote: > >> Not really, when you define the type "Maybe a": >> >> data Maybe a = Just a | Nothing >> >> Haskell is creating automatically two functions for you: >> >> Just :: a -> Maybe a >> Nothing :: Maybe a >> >> In the first case, you can think of "Just" and "Nothing" as a sort of tag >> identifying which element of the sum you have. >> It the second case it's a function, with the same name. >> A more informed person than me could say if they are indeed separated of >> if they are the same thing in GHC... >> >> >> On Thu, Mar 26, 2015 at 5:34 PM, Shishir Srivastava < >> shishir.srivastava at gmail.com> wrote: >> >>> isn't that then cyclic dependency between 'Maybe' and 'Just' ...where >>> the first one is defined in terms of second and vice-versa...? >>> >>> Shishir >>> >>> >>> On Thu, Mar 26, 2015 at 3:48 PM, Corentin Dupont < >>> corentin.dupont at gmail.com> wrote: >>> >>>> Hi Shishir, >>>> I think that's a legitimate question. >>>> >>>> By writing >>>> >>>> data Maybe a = a | Nothing >>>> >>>> you are saying that the type of the left hand side of the = is the same >>>> that right hand side (you are defining a type basically). >>>> Also you can only sum things of the same type. >>>> So you are saying: >>>> type "Maybe a" = type "a" >>>> Which is wrong. >>>> That's why "a" should be wrapped into something: >>>> type of "Just a" is indeed "Maybe a". >>>> >>>> "Just" is a type constructor: >>>> Just :: a -> Maybe a >>>> It allows you to build the Maybe. >>>> >>>> Said that, "Just" is a vocabulary choice. >>>> Personally I prefer the name choices of OCaml, Rust, Scala etc.: >>>> Option a = None | Some a >>>> >>>> >>>> >>>> On Thu, Mar 26, 2015 at 4:26 PM, Shishir Srivastava < >>>> shishir.srivastava at gmail.com> wrote: >>>> >>>>> ok..but what's with using the keyword 'Just' ? why cannot 'Maybe' be >>>>> defined like this >>>>> >>>>> data Maybe a = a | Nothing >>>>> >>>>> what's the point in having 'Just' keyword ? >>>>> >>>>> Shishir >>>>> >>>>> >>>>> On Thu, Mar 26, 2015 at 10:26 AM, Michael Alan Dorman < >>>>> mdorman at ironicdesign.com> wrote: >>>>> >>>>>> Shishir Srivastava writes: >>>>>> > After reading and re-reading the haskell tutorials I don't happen to >>>>>> > see a very convincing or appealing reason for having these data >>>>>> > types. >>>>>> >>>>>> To be clear: Maybe is the data *type*. Just and Nothing are its data >>>>>> *constructors*. >>>>>> >>>>>> > Can anyone please explain where Maybe and Just provide the sort of >>>>>> > functionality that cannot be achieved in other languages which don't >>>>>> > have these kind. >>>>>> >>>>>> The functionality can be achieved in other languages, certainly. The >>>>>> question is whether the clarity and safety is also achieved. >>>>>> >>>>>> When I see (as a totally contrived example): >>>>>> >>>>>> fopen :: Maybe FileHandle >>>>>> >>>>>> I know that that function may not be able to return a FileHandle value >>>>>> all the time. The compiler will, in fact, nag me if I do not write >>>>>> the >>>>>> code that calls it in such a way that it acknowledges that >>>>>> possibility. >>>>>> >>>>>> When I see: >>>>>> >>>>>> FILE * fopen ( const char * filename, const char * mode ); >>>>>> >>>>>> It is not immediately clear whether that can fail. Sure, we can make >>>>>> that inference, based on what we know about filesystems, etc., but the >>>>>> compiler is never going to complain if I ignore the possibility. >>>>>> >>>>>> In my experience, programmers in many languages end up resorting to >>>>>> convention to try and work around these sorts of ambiguities. Large >>>>>> projects have strategies for naming functions that try to pass along >>>>>> information out of band, or languages have a pervasive culture of >>>>>> "lint" >>>>>> tools that try to use heuristics to make up for what the type system >>>>>> doesn't make simple. >>>>>> >>>>>> That said, I know that doing Maybe sorts of things in languages that >>>>>> don't have, say, pattern matching, or the idea of a "failure monad", >>>>>> gets to be a drag very quickly---manually unwrapping things is at best >>>>>> awkward, having to re-wrap them just to unwrap them again in a >>>>>> sequence >>>>>> of computations quickly leads one to believe "it's just not worth >>>>>> it"---or you resort to exception handling, which has its own >>>>>> challenges >>>>>> to do well. >>>>>> >>>>>> Mike. >>>>>> >>>>> >>>>> >>>>> _______________________________________________ >>>>> Beginners mailing list >>>>> Beginners at haskell.org >>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>>> >>>>> >>>> >>> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mwm at mired.org Fri Mar 27 10:00:08 2015 From: mwm at mired.org (Mike Meyer) Date: Fri, 27 Mar 2015 05:00:08 -0500 Subject: [Haskell-beginners] Maybe and Just In-Reply-To: References: <87384soy0o.fsf@ironicdesign.com> Message-ID: On Fri, Mar 27, 2015 at 4:44 AM, Shishir Srivastava < shishir.srivastava at gmail.com> wrote: > Sorry, but I still have some grudges so to say with the way 'Maybe' is > defined. > > By definition '*Maybe*' takes a type parameter which I will denote here > as '*tp*' for the sake of clarity like below - > > data Maybe tp = Just tp | Nothing > > Therefore '*tp*' is not representing a value perse such as '3' or 'XYZ' > etc but a data type such as '*Int*', '*Char*' etc. > > But when we have to create a data type of '*Maybe*' we write '*Just 3*' > and not '*Just Int*' or '*Just Char*' which is how it's defined in the > definition (i.e. '*Just tp*' ) . > > It is this discrepancy in definition and the actual value creation which > is slightly troubling me. > This was already explained, all be it in passing. Maybe Int is a type. Just and and Nothing are functions. Nothing takes no arguments. Just takes a single argument of the type given. There IS no type that Just Int would represent. There are only the two types Int and Maybe Int. 3 is of type Int. Just 3 is of type Maybe Int. Nothing is of type Maybe Int as well. Going back to the notion of "type plus error value", Int is the type, and Maybe Int is the type with an error value, the error value being Nothing. It might be educational to look at a second example. Try the Either types, which are sometimes used in a manner similar to the Maybe types. But instead of Nothing to indicate "an error occurred", you have Left tp to indicate that an error occurred using the value of tp to provide information about the error. -------------- next part -------------- An HTML attachment was scrubbed... URL: From corentin.dupont at gmail.com Fri Mar 27 10:05:42 2015 From: corentin.dupont at gmail.com (Corentin Dupont) Date: Fri, 27 Mar 2015 11:05:42 +0100 Subject: [Haskell-beginners] Fwd: Maybe and Just In-Reply-To: References: <87384soy0o.fsf@ironicdesign.com> Message-ID: You're right, "Just" is used at two different levels, it's just that it have the same name is both cases. One is at type level, the other at value level. Since this is two separated levels, there is no risk of confusion and having the same name is fine. To be clear, you can write: data Maybe = Just Int | Nothing Then use it as: my_value = Just 3 It the first case, "Just" is a tag in the type definition, in the second case it's a function constructing a value. They just happen to have the same name (a choice of Haskell language). On Fri, Mar 27, 2015 at 10:44 AM, Shishir Srivastava < shishir.srivastava at gmail.com> wrote: > Sorry, but I still have some grudges so to say with the way 'Maybe' is > defined. > > By definition '*Maybe*' takes a type parameter which I will denote here > as '*tp*' for the sake of clarity like below - > > data Maybe tp = Just tp | Nothing > > Therefore '*tp*' is not representing a value perse such as '3' or 'XYZ' > etc but a data type such as '*Int*', '*Char*' etc. > > But when we have to create a data type of '*Maybe*' we write '*Just 3*' > and not '*Just Int*' or '*Just Char*' which is how it's defined in the > definition (i.e. '*Just tp*' ) . > > It is this discrepancy in definition and the actual value creation which > is slightly troubling me. > > Thanks, > Shishir > > Shishir Srivastava > +44 (0) 750 127 5019 > > > On Thu, Mar 26, 2015 at 5:31 PM, Corentin Dupont < > corentin.dupont at gmail.com> wrote: > >> Not really, when you define the type "Maybe a": >> >> data Maybe a = Just a | Nothing >> >> Haskell is creating automatically two functions for you: >> >> Just :: a -> Maybe a >> Nothing :: Maybe a >> >> In the first case, you can think of "Just" and "Nothing" as a sort of tag >> identifying which element of the sum you have. >> It the second case it's a function, with the same name. >> A more informed person than me could say if they are indeed separated of >> if they are the same thing in GHC... >> >> >> On Thu, Mar 26, 2015 at 5:34 PM, Shishir Srivastava < >> shishir.srivastava at gmail.com> wrote: >> >>> isn't that then cyclic dependency between 'Maybe' and 'Just' ...where >>> the first one is defined in terms of second and vice-versa...? >>> >>> Shishir >>> >>> >>> On Thu, Mar 26, 2015 at 3:48 PM, Corentin Dupont < >>> corentin.dupont at gmail.com> wrote: >>> >>>> Hi Shishir, >>>> I think that's a legitimate question. >>>> >>>> By writing >>>> >>>> data Maybe a = a | Nothing >>>> >>>> you are saying that the type of the left hand side of the = is the same >>>> that right hand side (you are defining a type basically). >>>> Also you can only sum things of the same type. >>>> So you are saying: >>>> type "Maybe a" = type "a" >>>> Which is wrong. >>>> That's why "a" should be wrapped into something: >>>> type of "Just a" is indeed "Maybe a". >>>> >>>> "Just" is a type constructor: >>>> Just :: a -> Maybe a >>>> It allows you to build the Maybe. >>>> >>>> Said that, "Just" is a vocabulary choice. >>>> Personally I prefer the name choices of OCaml, Rust, Scala etc.: >>>> Option a = None | Some a >>>> >>>> >>>> >>>> On Thu, Mar 26, 2015 at 4:26 PM, Shishir Srivastava < >>>> shishir.srivastava at gmail.com> wrote: >>>> >>>>> ok..but what's with using the keyword 'Just' ? why cannot 'Maybe' be >>>>> defined like this >>>>> >>>>> data Maybe a = a | Nothing >>>>> >>>>> what's the point in having 'Just' keyword ? >>>>> >>>>> Shishir >>>>> >>>>> >>>>> On Thu, Mar 26, 2015 at 10:26 AM, Michael Alan Dorman < >>>>> mdorman at ironicdesign.com> wrote: >>>>> >>>>>> Shishir Srivastava writes: >>>>>> > After reading and re-reading the haskell tutorials I don't happen to >>>>>> > see a very convincing or appealing reason for having these data >>>>>> > types. >>>>>> >>>>>> To be clear: Maybe is the data *type*. Just and Nothing are its data >>>>>> *constructors*. >>>>>> >>>>>> > Can anyone please explain where Maybe and Just provide the sort of >>>>>> > functionality that cannot be achieved in other languages which don't >>>>>> > have these kind. >>>>>> >>>>>> The functionality can be achieved in other languages, certainly. The >>>>>> question is whether the clarity and safety is also achieved. >>>>>> >>>>>> When I see (as a totally contrived example): >>>>>> >>>>>> fopen :: Maybe FileHandle >>>>>> >>>>>> I know that that function may not be able to return a FileHandle value >>>>>> all the time. The compiler will, in fact, nag me if I do not write >>>>>> the >>>>>> code that calls it in such a way that it acknowledges that >>>>>> possibility. >>>>>> >>>>>> When I see: >>>>>> >>>>>> FILE * fopen ( const char * filename, const char * mode ); >>>>>> >>>>>> It is not immediately clear whether that can fail. Sure, we can make >>>>>> that inference, based on what we know about filesystems, etc., but the >>>>>> compiler is never going to complain if I ignore the possibility. >>>>>> >>>>>> In my experience, programmers in many languages end up resorting to >>>>>> convention to try and work around these sorts of ambiguities. Large >>>>>> projects have strategies for naming functions that try to pass along >>>>>> information out of band, or languages have a pervasive culture of >>>>>> "lint" >>>>>> tools that try to use heuristics to make up for what the type system >>>>>> doesn't make simple. >>>>>> >>>>>> That said, I know that doing Maybe sorts of things in languages that >>>>>> don't have, say, pattern matching, or the idea of a "failure monad", >>>>>> gets to be a drag very quickly---manually unwrapping things is at best >>>>>> awkward, having to re-wrap them just to unwrap them again in a >>>>>> sequence >>>>>> of computations quickly leads one to believe "it's just not worth >>>>>> it"---or you resort to exception handling, which has its own >>>>>> challenges >>>>>> to do well. >>>>>> >>>>>> Mike. >>>>>> >>>>> >>>>> >>>>> _______________________________________________ >>>>> Beginners mailing list >>>>> Beginners at haskell.org >>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>>> >>>>> >>>> >>> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From akaberto at gmail.com Fri Mar 27 10:07:16 2015 From: akaberto at gmail.com (akash g) Date: Fri, 27 Mar 2015 15:37:16 +0530 Subject: [Haskell-beginners] Maybe and Just In-Reply-To: References: <87384soy0o.fsf@ironicdesign.com> Message-ID: Think of the Maybe type as -- Valid syntax with GADTs, I think data Maybe a where Nothing :: Maybe a Just :: a -> Maybe a You are confusing types with actual values : (Just 3) is a value with type, (Maybe Int). Think of it this way: A value is an object with some type and you have Maybe value constructors via Nothing and Just. On Fri, Mar 27, 2015 at 3:14 PM, Shishir Srivastava < shishir.srivastava at gmail.com> wrote: > Sorry, but I still have some grudges so to say with the way 'Maybe' is > defined. > > By definition '*Maybe*' takes a type parameter which I will denote here > as '*tp*' for the sake of clarity like below - > > data Maybe tp = Just tp | Nothing > > Therefore '*tp*' is not representing a value perse such as '3' or 'XYZ' > etc but a data type such as '*Int*', '*Char*' etc. > > But when we have to create a data type of '*Maybe*' we write '*Just 3*' > and not '*Just Int*' or '*Just Char*' which is how it's defined in the > definition (i.e. '*Just tp*' ) . > > It is this discrepancy in definition and the actual value creation which > is slightly troubling me. > > Thanks, > Shishir > > Shishir Srivastava > +44 (0) 750 127 5019 > > > On Thu, Mar 26, 2015 at 5:31 PM, Corentin Dupont < > corentin.dupont at gmail.com> wrote: > >> Not really, when you define the type "Maybe a": >> >> data Maybe a = Just a | Nothing >> >> Haskell is creating automatically two functions for you: >> >> Just :: a -> Maybe a >> Nothing :: Maybe a >> >> In the first case, you can think of "Just" and "Nothing" as a sort of tag >> identifying which element of the sum you have. >> It the second case it's a function, with the same name. >> A more informed person than me could say if they are indeed separated of >> if they are the same thing in GHC... >> >> >> On Thu, Mar 26, 2015 at 5:34 PM, Shishir Srivastava < >> shishir.srivastava at gmail.com> wrote: >> >>> isn't that then cyclic dependency between 'Maybe' and 'Just' ...where >>> the first one is defined in terms of second and vice-versa...? >>> >>> Shishir >>> >>> >>> On Thu, Mar 26, 2015 at 3:48 PM, Corentin Dupont < >>> corentin.dupont at gmail.com> wrote: >>> >>>> Hi Shishir, >>>> I think that's a legitimate question. >>>> >>>> By writing >>>> >>>> data Maybe a = a | Nothing >>>> >>>> you are saying that the type of the left hand side of the = is the same >>>> that right hand side (you are defining a type basically). >>>> Also you can only sum things of the same type. >>>> So you are saying: >>>> type "Maybe a" = type "a" >>>> Which is wrong. >>>> That's why "a" should be wrapped into something: >>>> type of "Just a" is indeed "Maybe a". >>>> >>>> "Just" is a type constructor: >>>> Just :: a -> Maybe a >>>> It allows you to build the Maybe. >>>> >>>> Said that, "Just" is a vocabulary choice. >>>> Personally I prefer the name choices of OCaml, Rust, Scala etc.: >>>> Option a = None | Some a >>>> >>>> >>>> >>>> On Thu, Mar 26, 2015 at 4:26 PM, Shishir Srivastava < >>>> shishir.srivastava at gmail.com> wrote: >>>> >>>>> ok..but what's with using the keyword 'Just' ? why cannot 'Maybe' be >>>>> defined like this >>>>> >>>>> data Maybe a = a | Nothing >>>>> >>>>> what's the point in having 'Just' keyword ? >>>>> >>>>> Shishir >>>>> >>>>> >>>>> On Thu, Mar 26, 2015 at 10:26 AM, Michael Alan Dorman < >>>>> mdorman at ironicdesign.com> wrote: >>>>> >>>>>> Shishir Srivastava writes: >>>>>> > After reading and re-reading the haskell tutorials I don't happen to >>>>>> > see a very convincing or appealing reason for having these data >>>>>> > types. >>>>>> >>>>>> To be clear: Maybe is the data *type*. Just and Nothing are its data >>>>>> *constructors*. >>>>>> >>>>>> > Can anyone please explain where Maybe and Just provide the sort of >>>>>> > functionality that cannot be achieved in other languages which don't >>>>>> > have these kind. >>>>>> >>>>>> The functionality can be achieved in other languages, certainly. The >>>>>> question is whether the clarity and safety is also achieved. >>>>>> >>>>>> When I see (as a totally contrived example): >>>>>> >>>>>> fopen :: Maybe FileHandle >>>>>> >>>>>> I know that that function may not be able to return a FileHandle value >>>>>> all the time. The compiler will, in fact, nag me if I do not write >>>>>> the >>>>>> code that calls it in such a way that it acknowledges that >>>>>> possibility. >>>>>> >>>>>> When I see: >>>>>> >>>>>> FILE * fopen ( const char * filename, const char * mode ); >>>>>> >>>>>> It is not immediately clear whether that can fail. Sure, we can make >>>>>> that inference, based on what we know about filesystems, etc., but the >>>>>> compiler is never going to complain if I ignore the possibility. >>>>>> >>>>>> In my experience, programmers in many languages end up resorting to >>>>>> convention to try and work around these sorts of ambiguities. Large >>>>>> projects have strategies for naming functions that try to pass along >>>>>> information out of band, or languages have a pervasive culture of >>>>>> "lint" >>>>>> tools that try to use heuristics to make up for what the type system >>>>>> doesn't make simple. >>>>>> >>>>>> That said, I know that doing Maybe sorts of things in languages that >>>>>> don't have, say, pattern matching, or the idea of a "failure monad", >>>>>> gets to be a drag very quickly---manually unwrapping things is at best >>>>>> awkward, having to re-wrap them just to unwrap them again in a >>>>>> sequence >>>>>> of computations quickly leads one to believe "it's just not worth >>>>>> it"---or you resort to exception handling, which has its own >>>>>> challenges >>>>>> to do well. >>>>>> >>>>>> Mike. >>>>>> >>>>> >>>>> >>>>> _______________________________________________ >>>>> Beginners mailing list >>>>> Beginners at haskell.org >>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>>> >>>>> >>>> >>> >> > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From shishir.srivastava at gmail.com Fri Mar 27 10:14:39 2015 From: shishir.srivastava at gmail.com (Shishir Srivastava) Date: Fri, 27 Mar 2015 10:14:39 +0000 Subject: [Haskell-beginners] Maybe and Just In-Reply-To: References: <87384soy0o.fsf@ironicdesign.com> Message-ID: Thanks Corentin. I think it makes more sense now that you've mentioned the fact that '*Just*' in the type definition of '*Maybe*' is only a *tag*. So would it be correct to re-define Maybe data type as follows - data Maybe tp = Justin tp | Nothing and then create the type value of *Maybe *as - *Just 3* *?* Shishir Srivastava +44 (0) 750 127 5019 On Fri, Mar 27, 2015 at 10:05 AM, Corentin Dupont wrote: > > You're right, "Just" is used at two different levels, it's just that it > have the same name is both cases. > One is at type level, the other at value level. > Since this is two separated levels, there is no risk of confusion and > having the same name is fine. > > To be clear, you can write: > > data Maybe = Just Int | Nothing > > Then use it as: > > my_value = Just 3 > > It the first case, "Just" is a tag in the type definition, in the second > case it's a function constructing a value. > They just happen to have the same name (a choice of Haskell language). > > > On Fri, Mar 27, 2015 at 10:44 AM, Shishir Srivastava < > shishir.srivastava at gmail.com> wrote: > >> Sorry, but I still have some grudges so to say with the way 'Maybe' is >> defined. >> >> By definition '*Maybe*' takes a type parameter which I will denote here >> as '*tp*' for the sake of clarity like below - >> >> data Maybe tp = Just tp | Nothing >> >> Therefore '*tp*' is not representing a value perse such as '3' or 'XYZ' >> etc but a data type such as '*Int*', '*Char*' etc. >> >> But when we have to create a data type of '*Maybe*' we write '*Just 3*' >> and not '*Just Int*' or '*Just Char*' which is how it's defined in the >> definition (i.e. '*Just tp*' ) . >> >> It is this discrepancy in definition and the actual value creation which >> is slightly troubling me. >> >> Thanks, >> Shishir >> >> Shishir Srivastava >> +44 (0) 750 127 5019 >> >> >> On Thu, Mar 26, 2015 at 5:31 PM, Corentin Dupont < >> corentin.dupont at gmail.com> wrote: >> >>> Not really, when you define the type "Maybe a": >>> >>> data Maybe a = Just a | Nothing >>> >>> Haskell is creating automatically two functions for you: >>> >>> Just :: a -> Maybe a >>> Nothing :: Maybe a >>> >>> In the first case, you can think of "Just" and "Nothing" as a sort of >>> tag identifying which element of the sum you have. >>> It the second case it's a function, with the same name. >>> A more informed person than me could say if they are indeed separated of >>> if they are the same thing in GHC... >>> >>> >>> On Thu, Mar 26, 2015 at 5:34 PM, Shishir Srivastava < >>> shishir.srivastava at gmail.com> wrote: >>> >>>> isn't that then cyclic dependency between 'Maybe' and 'Just' ...where >>>> the first one is defined in terms of second and vice-versa...? >>>> >>>> Shishir >>>> >>>> >>>> On Thu, Mar 26, 2015 at 3:48 PM, Corentin Dupont < >>>> corentin.dupont at gmail.com> wrote: >>>> >>>>> Hi Shishir, >>>>> I think that's a legitimate question. >>>>> >>>>> By writing >>>>> >>>>> data Maybe a = a | Nothing >>>>> >>>>> you are saying that the type of the left hand side of the = is the >>>>> same that right hand side (you are defining a type basically). >>>>> Also you can only sum things of the same type. >>>>> So you are saying: >>>>> type "Maybe a" = type "a" >>>>> Which is wrong. >>>>> That's why "a" should be wrapped into something: >>>>> type of "Just a" is indeed "Maybe a". >>>>> >>>>> "Just" is a type constructor: >>>>> Just :: a -> Maybe a >>>>> It allows you to build the Maybe. >>>>> >>>>> Said that, "Just" is a vocabulary choice. >>>>> Personally I prefer the name choices of OCaml, Rust, Scala etc.: >>>>> Option a = None | Some a >>>>> >>>>> >>>>> >>>>> On Thu, Mar 26, 2015 at 4:26 PM, Shishir Srivastava < >>>>> shishir.srivastava at gmail.com> wrote: >>>>> >>>>>> ok..but what's with using the keyword 'Just' ? why cannot 'Maybe' be >>>>>> defined like this >>>>>> >>>>>> data Maybe a = a | Nothing >>>>>> >>>>>> what's the point in having 'Just' keyword ? >>>>>> >>>>>> Shishir >>>>>> >>>>>> >>>>>> On Thu, Mar 26, 2015 at 10:26 AM, Michael Alan Dorman < >>>>>> mdorman at ironicdesign.com> wrote: >>>>>> >>>>>>> Shishir Srivastava writes: >>>>>>> > After reading and re-reading the haskell tutorials I don't happen >>>>>>> to >>>>>>> > see a very convincing or appealing reason for having these data >>>>>>> > types. >>>>>>> >>>>>>> To be clear: Maybe is the data *type*. Just and Nothing are its data >>>>>>> *constructors*. >>>>>>> >>>>>>> > Can anyone please explain where Maybe and Just provide the sort of >>>>>>> > functionality that cannot be achieved in other languages which >>>>>>> don't >>>>>>> > have these kind. >>>>>>> >>>>>>> The functionality can be achieved in other languages, certainly. The >>>>>>> question is whether the clarity and safety is also achieved. >>>>>>> >>>>>>> When I see (as a totally contrived example): >>>>>>> >>>>>>> fopen :: Maybe FileHandle >>>>>>> >>>>>>> I know that that function may not be able to return a FileHandle >>>>>>> value >>>>>>> all the time. The compiler will, in fact, nag me if I do not write >>>>>>> the >>>>>>> code that calls it in such a way that it acknowledges that >>>>>>> possibility. >>>>>>> >>>>>>> When I see: >>>>>>> >>>>>>> FILE * fopen ( const char * filename, const char * mode ); >>>>>>> >>>>>>> It is not immediately clear whether that can fail. Sure, we can make >>>>>>> that inference, based on what we know about filesystems, etc., but >>>>>>> the >>>>>>> compiler is never going to complain if I ignore the possibility. >>>>>>> >>>>>>> In my experience, programmers in many languages end up resorting to >>>>>>> convention to try and work around these sorts of ambiguities. Large >>>>>>> projects have strategies for naming functions that try to pass along >>>>>>> information out of band, or languages have a pervasive culture of >>>>>>> "lint" >>>>>>> tools that try to use heuristics to make up for what the type system >>>>>>> doesn't make simple. >>>>>>> >>>>>>> That said, I know that doing Maybe sorts of things in languages that >>>>>>> don't have, say, pattern matching, or the idea of a "failure monad", >>>>>>> gets to be a drag very quickly---manually unwrapping things is at >>>>>>> best >>>>>>> awkward, having to re-wrap them just to unwrap them again in a >>>>>>> sequence >>>>>>> of computations quickly leads one to believe "it's just not worth >>>>>>> it"---or you resort to exception handling, which has its own >>>>>>> challenges >>>>>>> to do well. >>>>>>> >>>>>>> Mike. >>>>>>> >>>>>> >>>>>> >>>>>> _______________________________________________ >>>>>> Beginners mailing list >>>>>> Beginners at haskell.org >>>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>>>> >>>>>> >>>>> >>>> >>> >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From timmelzer at gmail.com Fri Mar 27 12:31:03 2015 From: timmelzer at gmail.com (Norbert Melzer) Date: Fri, 27 Mar 2015 13:31:03 +0100 Subject: [Haskell-beginners] Writing a Parser with attoparsec that reads from a list of tokens Message-ID: Hi there! I want to write some small toy language using attoparsec. So I thought, first step tokenize. Let attoparsec consume the input stream and produce a list of tokens. Second step, parse tokens and produce the AST. Using parsec this would be possible easily and is documented. But I want to use attoparsec for this task, because I am interested in attoparsecs capability to have the input in chunks. TIA Norbert -------------- next part -------------- An HTML attachment was scrubbed... URL: From mrz.vtl at gmail.com Fri Mar 27 13:38:50 2015 From: mrz.vtl at gmail.com (Maurizio Vitale) Date: Fri, 27 Mar 2015 09:38:50 -0400 Subject: [Haskell-beginners] parser frontend Message-ID: G'day, I'm trying to decide how to architect the frontend of a compiler I'm using as an excuse for learning Haskell. Suppose we have a language (SystemVerilog) that has the notion of multi-file compilation units. This means that specific subset of files form separate scopes for certain things. For instance if we represent with lists of lists compilation units: [[a,b,c], [d], [e,f]] a macro definition in file b, would affect the rest of the file and file c, but wouldn't have effect on files d,e or a. Furthermore, if a toplevel construct is split between two files, say c and d, the compiler should treat the original compilation unit specification as if it was: [[a,b,(c,d)][e,f]], where (c,d) means we're compiling the logical concatenation of c and d. If (c,d) is also incomplete, (c,d,e) should be tried and so on. Now in well designed systems, all files can actually be compiled in parallel and so I'd like to optimize for that case and recompile files (either because we need side effects from files before them or because they're incomplete. So I'm not to concerned if wasted work is done for the degenerate cases. Any suggestion on how to go about this? Le's assume that parsing a file is done with a function: p :: file -> Either Error (ast, [defs], [use]) where the [defs] are things that might affects files down the line and [use] are things that, if defined by some prior file, cause recompilation. I'm interested in both a sequential and parallel solution and it would be sweet if they where similar, with the proper abstractions. Thanks a lot for any insight/ideas, Maurizio -------------- next part -------------- An HTML attachment was scrubbed... URL: From hjgtuyl at chello.nl Fri Mar 27 15:08:45 2015 From: hjgtuyl at chello.nl (Henk-Jan van Tuyl) Date: Fri, 27 Mar 2015 16:08:45 +0100 Subject: [Haskell-beginners] Writing a Parser with attoparsec that reads from a list of tokens In-Reply-To: References: Message-ID: On Fri, 27 Mar 2015 13:31:03 +0100, Norbert Melzer wrote: > Hi there! > > I want to write some small toy language using attoparsec. > > So I thought, first step tokenize. Let attoparsec consume the input > stream > and produce a list of tokens. > Second step, parse tokens and produce the AST. > > Using parsec this would be possible easily and is documented. But I want > to > use attoparsec for this task, because I am interested in attoparsecs > capability to have the input in chunks. You can use the list of reverse dependencies for attoparsec http://packdeps.haskellers.com/reverse/attoparsec to find usage examples. Regards, Henk-Jan van Tuyl -- Folding at home What if you could share your unused computer power to help find a cure? In just 5 minutes you can join the world's biggest networked computer and get us closer sooner. Watch the video. http://folding.stanford.edu/ http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html Haskell programming -- From edwards.benj at gmail.com Fri Mar 27 15:20:37 2015 From: edwards.benj at gmail.com (Benjamin Edwards) Date: Fri, 27 Mar 2015 15:20:37 +0000 Subject: [Haskell-beginners] Writing a Parser with attoparsec that reads from a list of tokens In-Reply-To: References: Message-ID: The thing is you can write parsers for tokens, then write parsers that consume those tokens by exclusively using the token parsers as the building blocks rather than the raw steam, all using the same combinators and mechanisms. This is much more flexible. Ben On Fri, 27 Mar 2015 at 15:08 Henk-Jan van Tuyl wrote: > On Fri, 27 Mar 2015 13:31:03 +0100, Norbert Melzer > wrote: > > > Hi there! > > > > I want to write some small toy language using attoparsec. > > > > So I thought, first step tokenize. Let attoparsec consume the input > > stream > > and produce a list of tokens. > > Second step, parse tokens and produce the AST. > > > > Using parsec this would be possible easily and is documented. But I want > > to > > use attoparsec for this task, because I am interested in attoparsecs > > capability to have the input in chunks. > > You can use the list of reverse dependencies for attoparsec > http://packdeps.haskellers.com/reverse/attoparsec > to find usage examples. > > Regards, > Henk-Jan van Tuyl > > > -- > Folding at home > What if you could share your unused computer power to help find a cure? In > just 5 minutes you can join the world's biggest networked computer and get > us closer sooner. Watch the video. > http://folding.stanford.edu/ > > > http://Van.Tuyl.eu/ > http://members.chello.nl/hjgtuyl/tourdemonad.html > Haskell programming > -- > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From joel.neely at gmail.com Fri Mar 27 19:01:56 2015 From: joel.neely at gmail.com (Joel Neely) Date: Fri, 27 Mar 2015 14:01:56 -0500 Subject: [Haskell-beginners] Maybe and Just In-Reply-To: References: <87384soy0o.fsf@ironicdesign.com> Message-ID: Shishir, Would I be right to guess that you're coming from an OO background? If so, I'd suggest thinking about the difference between declaring a constructor and invoking it. I suggest that you can read the Haskell declaration data Maybe tp = Just tp | Nothing as declaring ?a data type and specifying two constructors that can return an instance (in the OO sense of the word) of that data type. But when the expression Just "FOO" is invoking one of those constructors on a value of type String, so the resulting value has type Maybe String. Because Maybe is an instance of Show (in the Haskell sense of the word), there's a show function that can be applied to that value to produce something that looks like the line above. That's roughly equivalent to having a toString method on a Java class that returns a string that looks like a constructor call that could produce the actual object. -jn- On Fri, Mar 27, 2015 at 5:14 AM, Shishir Srivastava < shishir.srivastava at gmail.com> wrote: > Thanks Corentin. I think it makes more sense now that you've mentioned the > fact that '*Just*' in the type definition of '*Maybe*' is only a *tag*. > > So would it be correct to re-define Maybe data type as follows - > > data Maybe tp = Justin tp | Nothing > > and then create the type value of *Maybe *as - > > *Just 3* > > *?* > > > > Shishir Srivastava > +44 (0) 750 127 5019 > > > On Fri, Mar 27, 2015 at 10:05 AM, Corentin Dupont < > corentin.dupont at gmail.com> wrote: > >> >> You're right, "Just" is used at two different levels, it's just that it >> have the same name is both cases. >> One is at type level, the other at value level. >> Since this is two separated levels, there is no risk of confusion and >> having the same name is fine. >> >> To be clear, you can write: >> >> data Maybe = Just Int | Nothing >> >> Then use it as: >> >> my_value = Just 3 >> >> It the first case, "Just" is a tag in the type definition, in the second >> case it's a function constructing a value. >> They just happen to have the same name (a choice of Haskell language). >> >> >> On Fri, Mar 27, 2015 at 10:44 AM, Shishir Srivastava < >> shishir.srivastava at gmail.com> wrote: >> >>> Sorry, but I still have some grudges so to say with the way 'Maybe' is >>> defined. >>> >>> By definition '*Maybe*' takes a type parameter which I will denote here >>> as '*tp*' for the sake of clarity like below - >>> >>> data Maybe tp = Just tp | Nothing >>> >>> Therefore '*tp*' is not representing a value perse such as '3' or 'XYZ' >>> etc but a data type such as '*Int*', '*Char*' etc. >>> >>> But when we have to create a data type of '*Maybe*' we write '*Just 3*' >>> and not '*Just Int*' or '*Just Char*' which is how it's defined in the >>> definition (i.e. '*Just tp*' ) . >>> >>> It is this discrepancy in definition and the actual value creation which >>> is slightly troubling me. >>> >>> Thanks, >>> Shishir >>> >>> Shishir Srivastava >>> +44 (0) 750 127 5019 >>> >>> >>> On Thu, Mar 26, 2015 at 5:31 PM, Corentin Dupont < >>> corentin.dupont at gmail.com> wrote: >>> >>>> Not really, when you define the type "Maybe a": >>>> >>>> data Maybe a = Just a | Nothing >>>> >>>> Haskell is creating automatically two functions for you: >>>> >>>> Just :: a -> Maybe a >>>> Nothing :: Maybe a >>>> >>>> In the first case, you can think of "Just" and "Nothing" as a sort of >>>> tag identifying which element of the sum you have. >>>> It the second case it's a function, with the same name. >>>> A more informed person than me could say if they are indeed separated >>>> of if they are the same thing in GHC... >>>> >>>> >>>> On Thu, Mar 26, 2015 at 5:34 PM, Shishir Srivastava < >>>> shishir.srivastava at gmail.com> wrote: >>>> >>>>> isn't that then cyclic dependency between 'Maybe' and 'Just' ...where >>>>> the first one is defined in terms of second and vice-versa...? >>>>> >>>>> Shishir >>>>> >>>>> >>>>> On Thu, Mar 26, 2015 at 3:48 PM, Corentin Dupont < >>>>> corentin.dupont at gmail.com> wrote: >>>>> >>>>>> Hi Shishir, >>>>>> I think that's a legitimate question. >>>>>> >>>>>> By writing >>>>>> >>>>>> data Maybe a = a | Nothing >>>>>> >>>>>> you are saying that the type of the left hand side of the = is the >>>>>> same that right hand side (you are defining a type basically). >>>>>> Also you can only sum things of the same type. >>>>>> So you are saying: >>>>>> type "Maybe a" = type "a" >>>>>> Which is wrong. >>>>>> That's why "a" should be wrapped into something: >>>>>> type of "Just a" is indeed "Maybe a". >>>>>> >>>>>> "Just" is a type constructor: >>>>>> Just :: a -> Maybe a >>>>>> It allows you to build the Maybe. >>>>>> >>>>>> Said that, "Just" is a vocabulary choice. >>>>>> Personally I prefer the name choices of OCaml, Rust, Scala etc.: >>>>>> Option a = None | Some a >>>>>> >>>>>> >>>>>> >>>>>> On Thu, Mar 26, 2015 at 4:26 PM, Shishir Srivastava < >>>>>> shishir.srivastava at gmail.com> wrote: >>>>>> >>>>>>> ok..but what's with using the keyword 'Just' ? why cannot 'Maybe' be >>>>>>> defined like this >>>>>>> >>>>>>> data Maybe a = a | Nothing >>>>>>> >>>>>>> what's the point in having 'Just' keyword ? >>>>>>> >>>>>>> Shishir >>>>>>> >>>>>>> >>>>>>> On Thu, Mar 26, 2015 at 10:26 AM, Michael Alan Dorman < >>>>>>> mdorman at ironicdesign.com> wrote: >>>>>>> >>>>>>>> Shishir Srivastava writes: >>>>>>>> > After reading and re-reading the haskell tutorials I don't happen >>>>>>>> to >>>>>>>> > see a very convincing or appealing reason for having these data >>>>>>>> > types. >>>>>>>> >>>>>>>> To be clear: Maybe is the data *type*. Just and Nothing are its >>>>>>>> data >>>>>>>> *constructors*. >>>>>>>> >>>>>>>> > Can anyone please explain where Maybe and Just provide the sort of >>>>>>>> > functionality that cannot be achieved in other languages which >>>>>>>> don't >>>>>>>> > have these kind. >>>>>>>> >>>>>>>> The functionality can be achieved in other languages, certainly. >>>>>>>> The >>>>>>>> question is whether the clarity and safety is also achieved. >>>>>>>> >>>>>>>> When I see (as a totally contrived example): >>>>>>>> >>>>>>>> fopen :: Maybe FileHandle >>>>>>>> >>>>>>>> I know that that function may not be able to return a FileHandle >>>>>>>> value >>>>>>>> all the time. The compiler will, in fact, nag me if I do not write >>>>>>>> the >>>>>>>> code that calls it in such a way that it acknowledges that >>>>>>>> possibility. >>>>>>>> >>>>>>>> When I see: >>>>>>>> >>>>>>>> FILE * fopen ( const char * filename, const char * mode ); >>>>>>>> >>>>>>>> It is not immediately clear whether that can fail. Sure, we can >>>>>>>> make >>>>>>>> that inference, based on what we know about filesystems, etc., but >>>>>>>> the >>>>>>>> compiler is never going to complain if I ignore the possibility. >>>>>>>> >>>>>>>> In my experience, programmers in many languages end up resorting to >>>>>>>> convention to try and work around these sorts of ambiguities. Large >>>>>>>> projects have strategies for naming functions that try to pass along >>>>>>>> information out of band, or languages have a pervasive culture of >>>>>>>> "lint" >>>>>>>> tools that try to use heuristics to make up for what the type system >>>>>>>> doesn't make simple. >>>>>>>> >>>>>>>> That said, I know that doing Maybe sorts of things in languages that >>>>>>>> don't have, say, pattern matching, or the idea of a "failure monad", >>>>>>>> gets to be a drag very quickly---manually unwrapping things is at >>>>>>>> best >>>>>>>> awkward, having to re-wrap them just to unwrap them again in a >>>>>>>> sequence >>>>>>>> of computations quickly leads one to believe "it's just not worth >>>>>>>> it"---or you resort to exception handling, which has its own >>>>>>>> challenges >>>>>>>> to do well. >>>>>>>> >>>>>>>> Mike. >>>>>>>> >>>>>>> >>>>>>> >>>>>>> _______________________________________________ >>>>>>> Beginners mailing list >>>>>>> Beginners at haskell.org >>>>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >>>>>>> >>>>>>> >>>>>> >>>>> >>>> >>> >> >> > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -- Beauty of style and harmony and grace and good rhythm depend on simplicity. - Plato -------------- next part -------------- An HTML attachment was scrubbed... URL: From cppljevans at suddenlink.net Fri Mar 27 19:57:00 2015 From: cppljevans at suddenlink.net (Larry Evans) Date: Fri, 27 Mar 2015 14:57:00 -0500 Subject: [Haskell-beginners] Maybe and Just In-Reply-To: References: <87384soy0o.fsf@ironicdesign.com> Message-ID: <5515B60C.3040005@suddenlink.net> On 03/27/2015 02:01 PM, Joel Neely wrote: > Shishir, > > Would I be right to guess that you're coming from an OO background? If > so, I'd suggest thinking about the difference between declaring a > constructor and invoking it. > > I suggest that you can read the Haskell declaration > > data Maybe tp = Just tp | Nothing > > > as declaring ?a data type and specifying two constructors that can > return an instance (in the OO sense of the word) of that data type. But > when the expression > > Just "FOO" > > > is invoking one of those constructors on a value of type String, so the > resulting value has type Maybe String. > [snip] Or, Maybe can be thought of as an abstract class with concrete subclasses, Just and Nothing. Or, Maybe can be thought of like a tagged union. In c++ syntax: enum MaybeTag{ JustTag, NothingTag}; template struct JustType { ValType my_val; JustType(ValType a_val) : my_val(a_val) {} }; struct NothingType {}; template struct Maybe { private: MaybeTag my_tag; union possible_values { JustType just_val; NothingType nothing_val; possible_values(ValType a_val) : just_val(a_val) {} possible_values() : nothing_val() {} } my_val; Maybe(ValType a_val) : my_tag(JustTag) , my_val(a_val) { } Maybe() : my_tag(NothingTag) , my_val() {} public: MaybeTag tag()const { return my_tag; } static Maybe Just(ValType a_val) { return Maybe(a_val); } static Maybe Nothing() { return Maybe(); } }; #include int main() { auto mj=Maybe::Just(5); std::cout<<"mj.tag="<::Nothing(); std::cout<<"mn.tag="< I was implementing automatic differentiation in haskell and was able to code the calculation part, but I wanted to extend it to show the symbols instead of just the final value. Let me explain and copy/paste the code? 3 data ADif a = ADif a a deriving (Eq) 10 instance Floating x => Floating (ADif x) where 11 pi = ADif pi 0 12 exp (ADif x x') = ADif (exp x) (x' * exp x) 13 log (ADif x x') = ADif (log x) (x' / x) 14 sqrt (ADif x x') = ADif (sqrt x) (x' / (2 * sqrt x)) 15 sin (ADif x x') = ADif (sin x) (x' * cos x) 16 cos (ADif x x') = ADif (cos x) (x' * (- sin x)) ?.And so on all the functions 27 instance Num x => Num (ADif x) where 28 ADif x x' + ADif y y' = ADif (x+y) (x'+y') 29 ADif x x' * ADif y y' = ADif (x*y) (y'*x + x'*y) 30 fromInteger x = fromInteger x let myfunction x = exp (log (sin x)) *Main> myfunction (ADif 2 1) -0.4161468365471424 I verified that this is the correct solution by hand! (& well mathematica too!) Anyway now I was hoping to print the actual symbols, so I was googling around for extending ?Show? typeclass for floating and Num, kinda similar pattern. Is this the right approach? Or I need to rethink the problem? Basically my aim is to do something like mathematica where if I specify D[f[x],x] then I get the answer in symbols. -Animesh From chaddai.fouche at gmail.com Sat Mar 28 07:19:06 2015 From: chaddai.fouche at gmail.com (=?UTF-8?B?Q2hhZGRhw68gRm91Y2jDqQ==?=) Date: Sat, 28 Mar 2015 08:19:06 +0100 Subject: [Haskell-beginners] Automatic Differentiation In-Reply-To: References: Message-ID: On Sat, Mar 28, 2015 at 5:10 AM, Animesh Saxena wrote: > I was implementing automatic differentiation in haskell and was able to > code the calculation part, but I wanted to extend it to show the symbols > instead of just the final value. > > Anyway now I was hoping to print the actual symbols, so I was googling > around for extending ?Show? typeclass for floating and Num, kinda similar > pattern. Is this the right approach? Or I need to rethink the problem? > Basically my aim is to do something like mathematica where if I specify > D[f[x],x] then I get the answer in symbols. > > The idea would be to write a new type that transport an human readable representation as well as the actual value, then make it a Num, Floating and so on instance so that you could just use ADif with this type to get a representation of your action. You can look at simple-reflect for a simple implementation of this idea you can directly use with your ADif. If instead of a String, you transport an operation tree, you may even simplify your result and get back almost a symbolic differentiation from your automatic differentiation ! -- Jeda? -------------- next part -------------- An HTML attachment was scrubbed... URL: From k-bx at k-bx.com Sat Mar 28 11:13:55 2015 From: k-bx at k-bx.com (Konstantine Rybnikov) Date: Sat, 28 Mar 2015 13:13:55 +0200 Subject: [Haskell-beginners] parser frontend In-Reply-To: References: Message-ID: Maurizio, It's not completely clear how your compiler knows which files depend on which. Does it read files one by one and "updates" dependency list? What about situation when toplevel construct is split in two files, how does this single-file API handle it? On Fri, Mar 27, 2015 at 3:38 PM, Maurizio Vitale wrote: > G'day, > I'm trying to decide how to architect the frontend of a compiler I'm > using as an excuse for learning Haskell. > > Suppose we have a language (SystemVerilog) that has the notion of > multi-file compilation units. > This means that specific subset of files form separate scopes for certain > things. > For instance if we represent with lists of lists compilation units: > [[a,b,c], [d], [e,f]] > a macro definition in file b, would affect the rest of the file and file > c, but wouldn't have effect on files d,e or a. > > Furthermore, if a toplevel construct is split between two files, say c and > d, the compiler should treat the original compilation unit specification as > if it was: > [[a,b,(c,d)][e,f]], where (c,d) means we're compiling the logical > concatenation of c and d. > If (c,d) is also incomplete, (c,d,e) should be tried and so on. > > Now in well designed systems, all files can actually be compiled in > parallel and so I'd like to optimize for that case and recompile files > (either because we need side effects from files before them or because > they're incomplete. So I'm not to concerned if wasted work is done for the > degenerate cases. > > Any suggestion on how to go about this? > Le's assume that parsing a file is done with a function: > p :: file -> Either Error (ast, [defs], [use]) where the [defs] are things > that might affects files down the line and [use] are things that, if > defined by some prior file, cause recompilation. > > I'm interested in both a sequential and parallel solution and it would be > sweet if they where similar, with the proper abstractions. > > Thanks a lot for any insight/ideas, > > Maurizio > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mrz.vtl at gmail.com Sat Mar 28 14:56:04 2015 From: mrz.vtl at gmail.com (Maurizio Vitale) Date: Sat, 28 Mar 2015 10:56:04 -0400 Subject: [Haskell-beginners] parser frontend In-Reply-To: References: Message-ID: I did some reading and realized that the question is a bit too wide. I've got now Simon Marlow's book on parallel/concurrent haskell and going through it. Files depend on each other because one defines something that the other uses. There's more in SystemVerilog, but assume #define and #ifdef pairs. So the dependency is only implicit: you know it only after you've parsed both files. Nevertheless, a well organized system will #include files with definitions (and do the same for other SystemVerilog things that cause dependencies) so I'm ok with optimistically assume no dependency and compute a list of "problems" that cause recompilation. So if: file A: ... #define foo ... file B: ... #ifdef foo ... #endif ... and the command line has the order fileA, fileB we compile both files in parallel, but the result of compiling A will be (ast, [foo], []) and the result of compiling B will be (ast/Error, [], [foo]) since foo is in the use list of B and in the def list of A we know we have to recompile B (and compiling B doesn't pass a def list to a possible C until we're satisfied with it). So when there're dependencies, I'm ok with recompiling multiple times. As for the second question, splitting a toplevel across files is even more perverse and should be extremely rare (I think is there only for historical reasons: the first Verilog simulators assumed the entire design available and basically did a 'cat f1..fN' before compiling. Again, I'm happy with redo work in this case. If compilation units are [ [a,b,c], [d,e] ] and you have a parse error in c after having consumed the entire file and d has also a parse error, we restart with a new specification [ [a,b,(c,d)] [e]] where (c,d) means concatenation of the content of file c and d. Parse for a and b are still valid. Parse for e might be valid. But even if we invalidate and redo everything in exchange for simple code, I'm ok with it. My question can be abstracted a bit more in terms of list processing. We have a list of lists [[a]]. We need to process each leaf element by mapping a function p a e which process an element of type 'a' in an environment 'e' which comes form the evaluation of previous elements. Up to here, would be normal monadic code to hide 'e'. In addition since in our domain, we assume 'e' `intersect` 'u' is often empty (where 'u' are the uses that we discover while processing an element) we'd like to start the processing of all elements in parallel and redo the ones that turned out to be invalidated by previous ones. I'd like to find a solution to this that is in good Haskell style. We can forget the toplevel split across files for now, that's can be dealt in a outer layer that restarts everything throwing away all the work. On Sat, Mar 28, 2015 at 7:13 AM, Konstantine Rybnikov wrote: > Maurizio, > > It's not completely clear how your compiler knows which files depend on > which. Does it read files one by one and "updates" dependency list? What > about situation when toplevel construct is split in two files, how does > this single-file API handle it? > > On Fri, Mar 27, 2015 at 3:38 PM, Maurizio Vitale > wrote: > >> G'day, >> I'm trying to decide how to architect the frontend of a compiler I'm >> using as an excuse for learning Haskell. >> >> Suppose we have a language (SystemVerilog) that has the notion of >> multi-file compilation units. >> This means that specific subset of files form separate scopes for certain >> things. >> For instance if we represent with lists of lists compilation units: >> [[a,b,c], [d], [e,f]] >> a macro definition in file b, would affect the rest of the file and file >> c, but wouldn't have effect on files d,e or a. >> >> Furthermore, if a toplevel construct is split between two files, say c >> and d, the compiler should treat the original compilation unit >> specification as if it was: >> [[a,b,(c,d)][e,f]], where (c,d) means we're compiling the logical >> concatenation of c and d. >> If (c,d) is also incomplete, (c,d,e) should be tried and so on. >> >> Now in well designed systems, all files can actually be compiled in >> parallel and so I'd like to optimize for that case and recompile files >> (either because we need side effects from files before them or because >> they're incomplete. So I'm not to concerned if wasted work is done for the >> degenerate cases. >> >> Any suggestion on how to go about this? >> Le's assume that parsing a file is done with a function: >> p :: file -> Either Error (ast, [defs], [use]) where the [defs] are >> things that might affects files down the line and [use] are things that, if >> defined by some prior file, cause recompilation. >> >> I'm interested in both a sequential and parallel solution and it would be >> sweet if they where similar, with the proper abstractions. >> >> Thanks a lot for any insight/ideas, >> >> Maurizio >> >> _______________________________________________ >> Beginners mailing list >> Beginners at haskell.org >> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners >> >> > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mrz.vtl at gmail.com Sat Mar 28 19:40:18 2015 From: mrz.vtl at gmail.com (Maurizio Vitale) Date: Sat, 28 Mar 2015 15:40:18 -0400 Subject: [Haskell-beginners] parser frontend In-Reply-To: References: Message-ID: I think this goes a very long way towards what I need: https://github.com/ekmett/speculation If anybody has any suggestion on other libraries that can be of use when trying to parallelize a parser, I'd be very interested in hearing it. Thanks, Maurizio On Fri, Mar 27, 2015 at 9:38 AM, Maurizio Vitale wrote: > G'day, > I'm trying to decide how to architect the frontend of a compiler I'm > using as an excuse for learning Haskell. > > Suppose we have a language (SystemVerilog) that has the notion of > multi-file compilation units. > This means that specific subset of files form separate scopes for certain > things. > For instance if we represent with lists of lists compilation units: > [[a,b,c], [d], [e,f]] > a macro definition in file b, would affect the rest of the file and file > c, but wouldn't have effect on files d,e or a. > > Furthermore, if a toplevel construct is split between two files, say c and > d, the compiler should treat the original compilation unit specification as > if it was: > [[a,b,(c,d)][e,f]], where (c,d) means we're compiling the logical > concatenation of c and d. > If (c,d) is also incomplete, (c,d,e) should be tried and so on. > > Now in well designed systems, all files can actually be compiled in > parallel and so I'd like to optimize for that case and recompile files > (either because we need side effects from files before them or because > they're incomplete. So I'm not to concerned if wasted work is done for the > degenerate cases. > > Any suggestion on how to go about this? > Le's assume that parsing a file is done with a function: > p :: file -> Either Error (ast, [defs], [use]) where the [defs] are things > that might affects files down the line and [use] are things that, if > defined by some prior file, cause recompilation. > > I'm interested in both a sequential and parallel solution and it would be > sweet if they where similar, with the proper abstractions. > > Thanks a lot for any insight/ideas, > > Maurizio > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeffbrown.the at gmail.com Sun Mar 29 01:34:00 2015 From: jeffbrown.the at gmail.com (Jeffrey Brown) Date: Sat, 28 Mar 2015 18:34:00 -0700 Subject: [Haskell-beginners] failure $ cabal install wx Message-ID: Hi! I first sent this to Haskell-Cafe, then thought this would be a better destination. I switched OSs, from Ubuntu to OpenSuse 13.2, to fix some other problems. I since installed The Haskell Platform, and would like to install wxHaskell. The first time I tried that under OpenSuse, cabal install wx provided more output, installing a lot of things. Since then it has only given this: jeff at linux-ee07:~> cabal install wx Resolving dependencies... [1 of 1] Compiling Main ( /tmp/wxc-0.91.0.0-16672/wxc-0.91.0.0/Setup.hs, /tmp/wxc-0.91.0.0-16672/wxc-0.91.0.0/dist/setup/Main.o ) Linking /tmp/wxc-0.91.0.0-16672/wxc-0.91.0.0/dist/setup/setup ... Configuring wxc-0.91.0.0... Warning: No config found to match: /usr/bin/wx-config --version=2.9 --version-full in /usr/lib64/wx/config If you require this configuration, please install the desired library build. If this is part of an automated configuration test and no other errors occur, you may safely ignore it. You may use wx-config --list to see all configs available in the default prefix. readProcess failed: readProcess: wx-config "--version=2.9" "--version-full" (exit 1): failed Configuring wxc to build against wxWidgets 3.0.2.0 Building wxc /usr/bin/gcc -Wl,--hash-size=31 -Wl,--reduce-memory-overheads -Wl,--disable-new-dtags -Isrc/include -I/usr/include/wx-3.0 -I/usr/lib64/wx/include/gtk3-unicode-3.0 -D__WXGTK__ -DWXUSINGDLL -DwxDEBUG_LEVEL=0 -D_FILE_OFFSET_BITS=64 -DwxcREFUSE_MEDIACTRL -fPIC -c src/cpp/apppath.cpp -o dist/build/src/cpp/apppath.o gcc: error trying to exec 'cc1plus': execvp: No such file or directory Failed to install wxc-0.91.0.0 cabal: Error: some packages failed to install: wx-0.91.0.0 depends on wxc-0.91.0.0 which failed to install. wxc-0.91.0.0 failed during the building phase. The exception was: ExitFailure 1 wxcore-0.91.0.0 depends on wxc-0.91.0.0 which failed to install. jeff at linux-ee07:~> The file /usr/bin/wx-config exists. It may have gotten there today when I installed some wx packages via zypper (OpenSuse's equivalent to apt-get). I don't remember which those packages were, but in the wx-configg file appear these lines: this_version="3.0" [ -z "$output_option_release" ] || echo "3.0" [ -z "$output_option_version" ] || echo "3.0.2" [ -z "$output_option_version_full" ] || echo "3.0.2.0" so I believe the version of wx I have is 3.0.2.0. I'm using a Lenovo Thinkpad Edge 535 or 545. Thanks, Jeff -------------- next part -------------- An HTML attachment was scrubbed... URL: From allbery.b at gmail.com Sun Mar 29 01:38:27 2015 From: allbery.b at gmail.com (Brandon Allbery) Date: Sat, 28 Mar 2015 21:38:27 -0400 Subject: [Haskell-beginners] failure $ cabal install wx In-Reply-To: References: Message-ID: On Sat, Mar 28, 2015 at 9:34 PM, Jeffrey Brown wrote: > gcc: error trying to exec 'cc1plus': execvp: No such file or directory > That part at least is because installing gcc on SuSE doesn't install the C++ compiler components. You'll need to find the package containing the C++ components. -- brandon s allbery kf8nh sine nomine associates allbery.b at gmail.com ballbery at sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeffbrown.the at gmail.com Sun Mar 29 17:34:10 2015 From: jeffbrown.the at gmail.com (Jeffrey Brown) Date: Sun, 29 Mar 2015 10:34:10 -0700 Subject: [Haskell-beginners] failure $ cabal install wx In-Reply-To: References: Message-ID: Thank you, Brandon. I tried installing a ton of wx libraries via zypper, and it didn't work. Then I gave up and reverted to Kubuntu. On Sat, Mar 28, 2015 at 6:38 PM, Brandon Allbery wrote: > On Sat, Mar 28, 2015 at 9:34 PM, Jeffrey Brown > wrote: > >> gcc: error trying to exec 'cc1plus': execvp: No such file or directory >> > > That part at least is because installing gcc on SuSE doesn't install the > C++ compiler components. You'll need to find the package containing the C++ > components. > > -- > brandon s allbery kf8nh sine nomine > associates > allbery.b at gmail.com > ballbery at sinenomine.net > unix, openafs, kerberos, infrastructure, xmonad > http://sinenomine.net > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dot_wangyushi at yeah.net Mon Mar 30 06:22:20 2015 From: dot_wangyushi at yeah.net (m00nlight) Date: Mon, 30 Mar 2015 14:22:20 +0800 (CST) Subject: [Haskell-beginners] Arithmetic expression parsing problem Message-ID: <12e4319a.292.14c69585d2d.Coremail.dot_wangyushi@yeah.net> Dear Haskellers, I am new to programming in haskell, recently I came up with an task to write an simple arithemtic evaluator in haskell. I try to write it using Text.Parsec, it can handle binary operation and some unary operation, but will give information of parsing error in some case. The following is my code import Text.Parsec import Text.Parsec.Expr import Text.Parsec.Combinator import Data.Functor data Exp = Num Int | Add Exp Exp | Sub Exp Exp | Mul Exp Exp | Div Exp Exp | Pos Exp | Neg Exp expr = buildExpressionParser table factor table = [[op "*" (Mul) AssocRight, op "/" (Div) AssocRight] ,[op "+" (Add) AssocLeft, op "-" (Sub) AssocLeft] ,[prefix "-" (Neg), prefix "+" (Pos)]] where op s f assoc = Infix (f <$ string s) assoc prefix s f = Prefix (f <$ string s) factor = between (char '(') (char ')') expr <|> (Num . read <$> many1 digit) eval :: (Num a, Integral a) => Exp -> a eval e = case e of Num x -> fromIntegral x Pos a -> eval a Neg a -> negate $ eval a Add a b -> eval a + eval b Sub a b -> eval a - eval b Mul a b -> eval a * eval b Div a b -> eval a `div` eval b solution :: (Num a, Integral a) => String -> a solution = either (const (error "Did not parse")) eval . parse expr "" The following is some test, *Main> solution "-4/(2+3)" 0 *Main> solution "-4/(2-3)" 4 *Main> solution "-4/-2" *** Exception: Did not parse *Main> solution "16/-4" *** Exception: Did not parse *Main> solution "-16/4" -4 *Main> Can anyone teach me how to solve this? Thanks in advanced. --m00nlight -------------- next part -------------- An HTML attachment was scrubbed... URL: From fa-ml at ariis.it Mon Mar 30 07:05:14 2015 From: fa-ml at ariis.it (Francesco Ariis) Date: Mon, 30 Mar 2015 09:05:14 +0200 Subject: [Haskell-beginners] Arithmetic expression parsing problem In-Reply-To: <12e4319a.292.14c69585d2d.Coremail.dot_wangyushi@yeah.net> References: <12e4319a.292.14c69585d2d.Coremail.dot_wangyushi@yeah.net> Message-ID: <20150330070514.GA9832@x60s.casa> On Mon, Mar 30, 2015 at 02:22:20PM +0800, m00nlight wrote: > I am new to programming in haskell, recently I came up with an task to > write an simple arithemtic evaluator in haskell. I try to write it using > Text.Parsec, it can handle binary operation and some unary operation, > but will give information of parsing error in some case. The following > is my code > > [..] > Can anyone teach me how to solve this? Thanks in advanced. Hello, first things first, I slightly modified your `solution` function, so it can fail with meaningful error messages solution :: (Num a, Integral a) => String -> a solution = either (error . show) eval . parse expr "" Then I added to `` operators at the end of your parsing expression (again, for easier diagnostic). factor = between (char '(') (char ')') expr <|> (Num . read <$> many1 digit) "factor" expr = buildExpressionParser table factor "expr" Now the error message is: ?> solution "-4/-2" *** Exception: (line 1, column 4): unexpected "-" expecting factor So Parsec was expecting a "factor" element but found itself with '-'. The first alternative of factor is not what we want (an expression surrounded by parentheses). The second part should be it (a 'number'). Now it is easy to recognise the problem: `digit` only accepts digits and not '-' as a prefix. When parsing stuff, , small functions and early testing (with hspec[1]) saved me much time and pain debugging. [1] http://hspec.github.io/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: From dot_wangyushi at yeah.net Mon Mar 30 08:10:18 2015 From: dot_wangyushi at yeah.net (m00nlight) Date: Mon, 30 Mar 2015 16:10:18 +0800 (CST) Subject: [Haskell-beginners] Arithmetic expression parsing problem In-Reply-To: <20150330070514.GA9832@x60s.casa> References: <12e4319a.292.14c69585d2d.Coremail.dot_wangyushi@yeah.net> <20150330070514.GA9832@x60s.casa> Message-ID: <48ca1d90.323.14c69bb33cf.Coremail.dot_wangyushi@yeah.net> Hi Francesco, Thanks for your explaination, so how can I modify the parser to handle this case? Can you give me some more details of how to modify it? Thanks in advanced. --m00nlight ?2015?03?30 15?05?, "Francesco Ariis"??: On Mon, Mar 30, 2015 at 02:22:20PM +0800, m00nlight wrote: > I am new to programming in haskell, recently I came up with an task to > write an simple arithemtic evaluator in haskell. I try to write it using > Text.Parsec, it can handle binary operation and some unary operation, > but will give information of parsing error in some case. The following > is my code > > [..] > Can anyone teach me how to solve this? Thanks in advanced. Hello, first things first, I slightly modified your `solution` function, so it can fail with meaningful error messages solution :: (Num a, Integral a) => String -> a solution = either (error . show) eval . parse expr "" Then I added to `` operators at the end of your parsing expression (again, for easier diagnostic). factor = between (char '(') (char ')') expr <|> (Num . read <$> many1 digit) "factor" expr = buildExpressionParser table factor "expr" Now the error message is: ?> solution "-4/-2" *** Exception: (line 1, column 4): unexpected "-" expecting factor So Parsec was expecting a "factor" element but found itself with '-'. The first alternative of factor is not what we want (an expression surrounded by parentheses). The second part should be it (a 'number'). Now it is easy to recognise the problem: `digit` only accepts digits and not '-' as a prefix. When parsing stuff, , small functions and early testing (with hspec[1]) saved me much time and pain debugging. [1] http://hspec.github.io/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From martin.drautzburg at web.de Mon Mar 30 11:22:44 2015 From: martin.drautzburg at web.de (martin) Date: Mon, 30 Mar 2015 13:22:44 +0200 Subject: [Haskell-beginners] Why does QuickCheck insist on this class constraint? Message-ID: <55193204.90305@web.de> Hello all, Ghc complainend about Could not deduce (Arbitrary a1) arising from a use of ?arbitrary? Could not deduce (Eq a1) arising from a use of ?arbitrary? in the following code .. data CList a = CList [Change a] deriving Show instance (Arbitrary c, Eq c) => Arbitrary (CList c) where arbitrary = do ts <- orderedList :: Gen[Time] vs <- listOf arbitrary :: Arbitrary c => Gen [c] return $ CList $ zipWith (\t v -> Chg t v) (nub ts) vs instance (Arbitrary a, Eq a) => Arbitrary (Temporal a) where arbitrary = do d <- arbitrary (CList cs) <- arbitrary :: (Arbitrary a, Eq a) => Gen (CList a) -- <=== return (Temporal d cs) ..if I leave out the class constraints in the line maked with "<===". Why is that so, i.e. why isn't the constraint four lines up (in the instance declaration) sufficient? From fa-ml at ariis.it Mon Mar 30 11:38:04 2015 From: fa-ml at ariis.it (Francesco Ariis) Date: Mon, 30 Mar 2015 13:38:04 +0200 Subject: [Haskell-beginners] Arithmetic expression parsing problem In-Reply-To: <48ca1d90.323.14c69bb33cf.Coremail.dot_wangyushi@yeah.net> References: <12e4319a.292.14c69585d2d.Coremail.dot_wangyushi@yeah.net> <20150330070514.GA9832@x60s.casa> <48ca1d90.323.14c69bb33cf.Coremail.dot_wangyushi@yeah.net> Message-ID: <20150330113804.GA20503@x60s.casa> On Mon, Mar 30, 2015 at 04:10:18PM +0800, m00nlight wrote: > Hi Francesco, > > Thanks for your explaination, so how can I modify the parser to handle this case? > Can you give me some more details of how to modify it? > > Thanks in advanced. Can't now, but take a look at Parsec.Token.reservedOp! You might want to read what it does and use it instead of `string` From jeffbrown.the at gmail.com Tue Mar 31 02:14:35 2015 From: jeffbrown.the at gmail.com (Jeffrey Brown) Date: Mon, 30 Mar 2015 19:14:35 -0700 Subject: [Haskell-beginners] Mutable collection of gui objects (wxHaskell) Message-ID: Hi, On Github, Jeremy O'Donoghue provides wx example code. From his collection I am trying to modify Layout.hs [1] to permit a variable number, rather than a fixed number, of text entry boxes. I shrank the program, mostly by removing features, until it was this: main = start $ do f <- frame [text := "Layout test"] p <- panel f [] xinput <- textEntry p [text := "100"] yinput <- textEntry p [text := "100"] myVar <- varCreate [xinput,yinput] set f [ layout := container p $ margin 10 $ column 5 [boxed "coordinates" (grid 5 5 [[hfill $ widget xinput], [hfill $ widget yinput]] -- replacing ) ] ] return () I want to replace the line marked "replacing". Rather than hard-coding the number of text entry boxes (2), I want it to deal with a mutable collection of them, in myVar. I tried this: [ fmap (\e -> hfill $ widget e) $ varGet myVar ] and got this error: Layout.hs:23:11: Couldn't match type `IO' with `[]' Expected type: [Layout] Actual type: IO Layout In the expression: fmap (\ e -> hfill $ widget e) $ varGet myVar In the third argument of `grid', namely `[fmap (\ e -> hfill $ widget e) $ varGet myVar]' In the second argument of `boxed', namely `(grid 5 5 [fmap (\ e -> hfill $ widget e) $ varGet myVar])' So then I tried something I thought would be equivalent: [[ (hfill $ widget e) | e <- (varGet myVar)]] and got a different error: Layout.hs:23:39: Couldn't match expected type `[w0]' with actual type `IO [TextCtrl ()]' In the return type of a call of `varGet' In the expression: (varGet myVar) In a stmt of a list comprehension: e <- (varGet myVar) I kind of understand the problem is that when I varGet myVar, I end up with type IO Layout, rather than type Layout, but I don't know what to do about it. Thanks, Jeff [1] https://github.com/jodonoghue/wxHaskell/blob/master/samples/wx/Layout.hs -------------- next part -------------- An HTML attachment was scrubbed... URL: From tkoster at gmail.com Tue Mar 31 03:26:53 2015 From: tkoster at gmail.com (Thomas Koster) Date: Tue, 31 Mar 2015 14:26:53 +1100 Subject: [Haskell-beginners] Is there an aeson-like XML serialization library? Message-ID: Hi list, I want to write a simple XML web service in Haskell that services a .NET WCF client, but am struggling with choosing the right XML library. "aeson" [1] has been a pleasure to use, so I am looking for an XML serialization library similar to aeson, where I can write ToElement/FromElement instances using simple applicative combinators, working with a high-level document model (i.e. not a parse tree), just like I have done in the past with ToJSON/FromJSON. Does such a library exist? I need the library to understand XML namespaces and the mandatory predefined entities, but I do not need any other extensions like XML Schemas, XPath or XSLT. Preferably, "xmlns" attributes should be handled specially and namespace prefixes resolved by the parser. "xmlns" attributes should be placed automatically by the renderer (I don't care what prefixes it chooses). I do not want to have to keep track of seen namespace prefixes while I am traversing the document, or to manually place "xmlns" attributes on elements for rendering. The "xml" [2] library is giving me grief at the moment with how unspecial its treatment of namespaces is. HXT appears to be beyond my skill level at the moment. There appear to be too many new things I would have to learn all at once before I could use it for this simple task. Cf. aeson, which I was able to use for practical applications the day I learned what an applicative functor was. [1] https://hackage.haskell.org/package/aeson [2] https://hackage.haskell.org/package/xml Thanks, -- Thomas Koster -------------- next part -------------- An HTML attachment was scrubbed... URL: From martin.drautzburg at web.de Tue Mar 31 05:22:32 2015 From: martin.drautzburg at web.de (martin) Date: Tue, 31 Mar 2015 07:22:32 +0200 Subject: [Haskell-beginners] Arrow vs. function In-Reply-To: References: <55107AEC.6040705@web.de> Message-ID: <551A2F18.2040603@web.de> Am 03/23/2015 um 09:57 PM schrieb John Wiegley: >>>>>> martin writes: > >> But that's what a function does. So what's the fundamental difference >> between an arrow and a fuction? > > Arrows abstract functions, allowing you to have constructions like Kleisli, > which are Arrows, but compose in the presence of effects using (<=<) rather > than (.). I recall reading something like "under composition an arrow returns a new version of itself". It this correct? This would indeed be something a function does not do. From martin.drautzburg at web.de Tue Mar 31 05:33:56 2015 From: martin.drautzburg at web.de (martin) Date: Tue, 31 Mar 2015 07:33:56 +0200 Subject: [Haskell-beginners] Are Arrows good for simulation purposes Message-ID: <551A31C4.3030002@web.de> Hello all, little do I know about arrows, but the "stream processor" metaphor suggests, that they can be used to simulate a network of things, services or data. Is this correct? I came across the following thought: When I simulate a billard game with a DES, I would compute collisions of balls with each other and with the banks, creatign a set of events, of which only the earliest will be considered to compute the next state. This is pure DES and does not seem to be a good candidate for arrows. In this case I'd be more interested in composing collision detectors than in stream processing. OTOH, when I move parcels around and process then in various stages, then a "stream processor" would make perfect sense to me. In that case, would I abandon the DES paradigm entirely (including the notion of an event queue) and just model the network and let it run? From michael at snoyman.com Tue Mar 31 05:39:28 2015 From: michael at snoyman.com (Michael Snoyman) Date: Tue, 31 Mar 2015 05:39:28 +0000 Subject: [Haskell-beginners] Is there an aeson-like XML serialization library? In-Reply-To: References: Message-ID: It doesn't have the typeclass stuff built in, but xml-conduit has proper support for XML namespaces. On Tue, Mar 31, 2015, 6:27 AM Thomas Koster wrote: > Hi list, > > I want to write a simple XML web service in Haskell that services a .NET > WCF client, but am struggling with choosing the right XML library. > > "aeson" [1] has been a pleasure to use, so I am looking for an XML > serialization library similar to aeson, where I can write > ToElement/FromElement instances using simple applicative combinators, > working with a high-level document model (i.e. not a parse tree), just like > I have done in the past with ToJSON/FromJSON. > > Does such a library exist? > > I need the library to understand XML namespaces and the mandatory > predefined entities, but I do not need any other extensions like XML > Schemas, XPath or XSLT. Preferably, "xmlns" attributes should be handled > specially and namespace prefixes resolved by the parser. "xmlns" attributes > should be placed automatically by the renderer (I don't care what prefixes > it chooses). I do not want to have to keep track of seen namespace prefixes > while I am traversing the document, or to manually place "xmlns" attributes > on elements for rendering. The "xml" [2] library is giving me grief at the > moment with how unspecial its treatment of namespaces is. > > HXT appears to be beyond my skill level at the moment. There appear to be > too many new things I would have to learn all at once before I could use it > for this simple task. Cf. aeson, which I was able to use for practical > applications the day I learned what an applicative functor was. > > [1] https://hackage.haskell.org/package/aeson > [2] https://hackage.haskell.org/package/xml > > Thanks, > -- > Thomas Koster > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From hjgtuyl at chello.nl Tue Mar 31 07:48:54 2015 From: hjgtuyl at chello.nl (Henk-Jan van Tuyl) Date: Tue, 31 Mar 2015 09:48:54 +0200 Subject: [Haskell-beginners] Mutable collection of gui objects (wxHaskell) In-Reply-To: References: Message-ID: On Tue, 31 Mar 2015 04:14:35 +0200, Jeffrey Brown wrote: : > I am trying to modify Layout.hs [1] to permit a variable number, rather > than a fixed number, of text entry boxes. I shrank the program, mostly by > removing features, until it was this: > > main = start $ do > f <- frame [text := "Layout test"] > p <- panel f [] > xinput <- textEntry p [text := "100"] > yinput <- textEntry p [text := "100"] > myVar <- varCreate [xinput,yinput] > set f [ layout := container p $ margin 10 $ > column 5 [boxed "coordinates" (grid 5 5 > [[hfill $ widget xinput], [hfill $ widget yinput]] -- replacing > ) ] ] > return () > > I want to replace the line marked "replacing". Rather than hard-coding > the > number of text entry boxes (2), I want it to deal with a mutable > collection > of them, in myVar. > > I tried this: > [ fmap (\e -> hfill $ widget e) $ varGet myVar ] : The result of varGet is of type "IO something", you must convert that to "something", by using "<-". You can do this by adding the line: inputs <- map (\e -> [hfill $ widget e]) <$> varGet myVar before the set command (note the square brackets). The <$> operator is from module Data.Functor and is defined as (<$>) = fmap The main function becomes this: main = start $ do f <- frame [text := "Layout test"] p <- panel f [] xinput <- textEntry p [text := "100"] yinput <- textEntry p [text := "100"] myVar <- varCreate [xinput, yinput] inputs <- map (\e -> [hfill $ widget e]) <$> varGet myVar set f [ layout := container p $ margin 10 $ column 5 [boxed "coordinates" (grid 5 5 inputs)] ] return () Regards, Henk-Jan van Tuyl -- Folding at home What if you could share your unused computer power to help find a cure? In just 5 minutes you can join the world's biggest networked computer and get us closer sooner. Watch the video. http://folding.stanford.edu/ http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html Haskell programming -- From hjgtuyl at chello.nl Tue Mar 31 07:52:31 2015 From: hjgtuyl at chello.nl (Henk-Jan van Tuyl) Date: Tue, 31 Mar 2015 09:52:31 +0200 Subject: [Haskell-beginners] Mutable collection of gui objects (wxHaskell) In-Reply-To: References: Message-ID: On Tue, 31 Mar 2015 04:14:35 +0200, Jeffrey Brown wrote: > On Github, Jeremy O'Donoghue provides wx example code. From his > collection Note, that this repository is not actively maintained anymore, the official repository is at https://github.com/wxHaskell/wxHaskell Regards, Henk-Jan van Tuyl -- Folding at home What if you could share your unused computer power to help find a cure? In just 5 minutes you can join the world's biggest networked computer and get us closer sooner. Watch the video. http://folding.stanford.edu/ http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html Haskell programming -- From tkoster at gmail.com Tue Mar 31 09:54:40 2015 From: tkoster at gmail.com (Thomas Koster) Date: Tue, 31 Mar 2015 20:54:40 +1100 Subject: [Haskell-beginners] Is there an aeson-like XML serialization library? In-Reply-To: References: Message-ID: Michael, On 31 March 2015 at 14:26, Thomas Koster wrote: > I want to write a simple XML web service in Haskell that services a .NET > WCF client, but am struggling with choosing the right XML library. > ... > I need the library to understand XML namespaces and the mandatory > predefined entities, but I do not need any other extensions like XML > Schemas, XPath or XSLT. Preferably, "xmlns" attributes should be handled > specially and namespace prefixes resolved by the parser. "xmlns" attributes > should be placed automatically by the renderer (I don't care what prefixes > it chooses). I do not want to have to keep track of seen namespace prefixes > while I am traversing the document, or to manually place "xmlns" attributes > on elements for rendering. On 31 March 2015 at 16:39, Michael Snoyman wrote: > It doesn't have the typeclass stuff built in, but xml-conduit has proper > support for XML namespaces. That's OK. I can create the type classes myself. class ToElement a where toElement :: a -> Element class FromElement a where parseElement :: Element -> Either String a The important thing is that namespaces are understood so that I am able create instances that compose, e.g. (off the top of my head) data SoapEnvelope h b = SoapEnvelope { soapEnvelopeHeaders :: [h], soapEnvelopeBody :: b } instance (FromElement h, FromElement b) => FromElement (SoapEnvelope h b) where parseElement e = SoapEnvelope <$> (...headers...) <*> (...body...) Thanks, -- Thomas Koster -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeffbrown.the at gmail.com Tue Mar 31 20:11:47 2015 From: jeffbrown.the at gmail.com (Jeffrey Brown) Date: Tue, 31 Mar 2015 13:11:47 -0700 Subject: [Haskell-beginners] Mutable collection of gui objects (wxHaskell) In-Reply-To: References: Message-ID: It works! And I don't understand it! Particularly this line: inputs <- map (\e -> [hfill $ widget e]) <$> varGet myVar I'm considering the type signatures: map :: (a -> b) -> [a] -> [b] (<$>) :: Functor f => (a -> b) -> f a -> f b varGet :: Var a -> IO a map and <$> (fmap) are nearly synonymous; map seems like a special case of fmap. I gather the fmap must be to map inside the IO type that varGet returns, and the map must be mapping across some list. But what about their function arguments? Is map using the lambda expression, or is fmap? What function argument is the other one using? Are they both somehow sharing the lambda expression? On Tue, Mar 31, 2015 at 12:48 AM, Henk-Jan van Tuyl wrote: > On Tue, 31 Mar 2015 04:14:35 +0200, Jeffrey Brown > wrote: > > : > >> I am trying to modify Layout.hs [1] to permit a variable number, rather >> than a fixed number, of text entry boxes. I shrank the program, mostly by >> removing features, until it was this: >> >> main = start $ do >> f <- frame [text := "Layout test"] >> p <- panel f [] >> xinput <- textEntry p [text := "100"] >> yinput <- textEntry p [text := "100"] >> myVar <- varCreate [xinput,yinput] >> set f [ layout := container p $ margin 10 $ >> column 5 [boxed "coordinates" (grid 5 5 >> [[hfill $ widget xinput], [hfill $ widget yinput]] -- replacing >> ) ] ] >> return () >> >> I want to replace the line marked "replacing". Rather than hard-coding the >> number of text entry boxes (2), I want it to deal with a mutable >> collection >> of them, in myVar. >> >> I tried this: >> [ fmap (\e -> hfill $ widget e) $ varGet myVar ] >> > : > > The result of varGet is of type "IO something", you must convert that to > "something", by using "<-". You can do this by adding the line: > inputs <- map (\e -> [hfill $ widget e]) <$> varGet myVar > before the set command (note the square brackets). The <$> operator is > from module Data.Functor and is defined as > (<$>) = fmap > > The main function becomes this: > main = start $ do > f <- frame [text := "Layout test"] > p <- panel f [] > xinput <- textEntry p [text := "100"] > yinput <- textEntry p [text := "100"] > myVar <- varCreate [xinput, yinput] > inputs <- map (\e -> [hfill $ widget e]) <$> varGet myVar > set f [ layout := container p $ margin 10 $ > column 5 [boxed "coordinates" (grid 5 5 inputs)] > ] > return () > > > Regards, > Henk-Jan van Tuyl > > > -- > Folding at home > What if you could share your unused computer power to help find a cure? In > just 5 minutes you can join the world's biggest networked computer and get > us closer sooner. Watch the video. > http://folding.stanford.edu/ > > > http://Van.Tuyl.eu/ > http://members.chello.nl/hjgtuyl/tourdemonad.html > Haskell programming > -- > -------------- next part -------------- An HTML attachment was scrubbed... URL: From hjgtuyl at chello.nl Tue Mar 31 22:51:44 2015 From: hjgtuyl at chello.nl (Henk-Jan van Tuyl) Date: Wed, 01 Apr 2015 00:51:44 +0200 Subject: [Haskell-beginners] Mutable collection of gui objects (wxHaskell) In-Reply-To: References: Message-ID: On Tue, 31 Mar 2015 22:11:47 +0200, Jeffrey Brown wrote: > It works! And I don't understand it! Particularly this line: > > inputs <- map (\e -> [hfill $ widget e]) <$> varGet myVar > > I'm considering the type signatures: > map :: (a -> b) -> [a] -> [b] > (<$>) :: Functor f => (a -> b) -> f a -> f b > varGet :: Var a -> IO a > map and <$> (fmap) are nearly synonymous; map seems like a special case > of > fmap. I gather the fmap must be to map inside the IO type that varGet > returns, and the map must be mapping across some list. But what about > their > function arguments? Is map using the lambda expression, or is fmap? What > function argument is the other one using? Are they both somehow sharing > the > lambda expression? The expression f <$> x is equal to fmap f x . If f :: a -> b x :: IO a then fmap f :: IO a -> IO b . You could say, fmap lifts f to the IO monad (you could also use liftM for this). In your case, f is map (\e -> [hfill $ widget e]) and x is varGet myVar You stored a list of textEntrys in myVar, the lambda expression is mapped over this list. Another way to look at it: you can replace the line inputs <- map (\e -> [hfill $ widget e]) <$> varGet myVar with xs <- varGet myVar let inputs = map (\e -> [hfill $ widget e]) xs Regards, Henk-Jan van Tuyl -- Folding at home What if you could share your unused computer power to help find a cure? In just 5 minutes you can join the world's biggest networked computer and get us closer sooner. Watch the video. http://folding.stanford.edu/ http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html Haskell programming --