Why am I getting parse error in input function...what I am actually trying to do is finding the gcd of the list...pls help... Here is my Haskell Code... import System.IO
gcd :: Int -> Int -> Int gcd a b | b == 0 =a | otherwise = gcd b (a mod b)
answer :: List -> Int answer list = foldl (gcd) list
input :: Int -> List input n | n /= 0 s <- readLn return (words s) putStrLn answer s n = n - 1 input n
main=do hSetBuffering stdin LineBuffering n <- getLine if n /= 0 then putStrLn answer input nsubmitted by pvkcse
[link] [1 comment]
I've finally purchased a domain for myself and now I have a place to use as a showroom of my personal games, take a look (and download them): http://games.tnegri.com/
Also, my blog is now hosted at http://blog.tnegri.com/. Nice! Right?
My vacations are just starting out and I already have a new domain.
Also, bought a slackline starter kit (I will try it for the first time), a frisbee, a boomerang and a frescobol kit!
I'm so happy. :)
Happy holidays to everyone!
I gave my talk and the turnout was a bit disappointing. Only 6 people showed up, but it was still a good experience overall and a great way to ease myself into giving these kinds of talks. Plus, I have learned that scheduling a programming talk at 4pm on the Friday before Thanksgiving break is a bad idea if you want people to show up!
I will be giving the talk again some time in the spring and used the feedback from the audience and the experience of talking to improve my slides a bit more, but I would love to hear what you guys think I should add, remove, clarify, or whatever. You can check it out here on my website.
It was definitely a great experience and I couldn't have done it without all of you guys!submitted by samisafish69
[link] [4 comments]
I'd written this as a comment to a great post by /u/tailcalled but I think I was a bit late to the comments. I was wondering if anyone had any feedback on my understanding of the code and some of the questions generated in the process.
Let me see if I understand what I'm seeing.
You create Map data structures by calling the names and handles functions.
The data structures produced by calling names and handles are wrapped into a Table data type via the from function. Within the from function, a Table type is constructed using as a type parameter an anonymous function which itself takes a key argument and returns a lookup of that key within the map m.
The Table data type specification is written in 'record syntax', with a its two type variables (k and v used as parts of the definition of an anonymous function).
What I don't understand is how the Table type is being constructed with that anonymous function. (The fact that this could be done was new to me! Cool stuff). Is this function evaluated during construction, or is it lazy (e.g. will that anonymous function remain unexecuted until other code runs lookup?) Perhaps related, it looks like that anonymous function gets partially applied later on, and then composed into something else later.
The other part I don't understand is how join2 works, which is a good segue into the Applicative which I need to become more familiar with. Here is a shot at it:
The join2 function constrains the function parameter types (f a) on the typeclass Applicative. In its body, join2 uses the "," type constructor (function?) to construct a Tuple, The "," seems to be using as its parameters the two f a parameters of join2 (I'm not certain). Now in this case the two parameters of "," are functions, as used in the example:*Main> let table = join2 names' handles' *Main> :t table table :: Table Id ((FirstName, LastName), TwitterHandle)
which I would guess means that liftA2 together with "," could be described as doing the following "it applies the two functions, and tuples up their results." And within names' and handles' themselves, we're seeing the promotion of names and handles from Maps to Tables. Hence the return type f (a, b), which (I am guessing) is coaxed into type Table (\k -> f k <*> x k) by the typeclass instance instance Applicative (Table k). I am not certain how the instance and its function definition (Table f <*> Table x = Table (\k -> f k <*> x k)) fit together with the liftA2.
The author states that the original purpose converting from Map to Table is to be able to use the Applicative, or more specifically, to have a working implementation of pure. I am not sure how pure fits in.
I recognize I am also showing that my understanding of typeclasses is probably also weak. I tend to think of typeclass instances as "make a given operation operate this way on this type, that that way on that type.
 *Main> :t (,) (,) :: a -> b -> (a, b)
 Perhaps it is not applying them but sort of freezing them in their state for use later, or taking the two chunks of computation (the two f a functions that are arguments) and bundling them together
 I recall seeing this sort of "logic in the type" in this example, hopefully it is roughly analogous:
you can retrieve an element at an 'index' in a sum type if you convert an Int into an Enum ('toEnum') and return the result in a function whose return type is the sum type. I hope this is roughly analogous to what I'm seeing with the `T27 newtype ID = ID Int 28 deriving (Show, Num, Eq, Ord, Integral, Real, Enum) 29 30 data Person = John | Sarah | Susan 31 deriving (Show, Eq, Enum, Bounded) ... 47 personFromId :: ID -> Maybe Person 48 personFromId (ID i) | i <= 3 && i > 0 = Just (toEnum (i-1)) 49 | otherwise = Nothing nabokovian
[link] [3 comments]