From hosseinerohani at yahoo.com Sun Apr 8 10:14:02 2007 From: hosseinerohani at yahoo.com (aminagho) Date: Tue Apr 10 04:25:49 2007 Subject: [Hugs-users] list vs. atom Message-ID: <9892551.post@talk.nabble.com> what is the best way to distinguish atoms and lists in haskell? I mean How I can find out the variable is List or atom. I know we can use :t to define type but I cannot use this. I have to do it dynamically in my program. Thanks a lot for your attention. -- View this message in context: http://www.nabble.com/list-vs.-atom-tf3543626.html#a9892551 Sent from the Haskell - Hugs-Users mailing list archive at Nabble.com. From ndmitchell at gmail.com Tue Apr 10 06:31:03 2007 From: ndmitchell at gmail.com (Neil Mitchell) Date: Tue Apr 10 06:29:32 2007 Subject: [Hugs-users] list vs. atom In-Reply-To: <9892551.post@talk.nabble.com> References: <9892551.post@talk.nabble.com> Message-ID: <404396ef0704100331g46b0d372gffae6a7916287a1d@mail.gmail.com> Hi > what is the best way to distinguish atoms and lists in haskell? In a statically typed language everything is distinguished at compile time, you might want to rephrase your question - starting with what you are hoping to achieve, so someone can give you the Haskell way of doing this. Also you are likely to get much more success asking on haskell-cafe@haskell.org - this list is more for issues with using Hugs, rather than general Haskell questions. Thanks Neil > I mean How I can find out the variable is List or atom. > I know we can use :t to define type but I cannot use this. > I have to do it dynamically in my program. > Thanks a lot for your attention. > -- > View this message in context: http://www.nabble.com/list-vs.-atom-tf3543626.html#a9892551 > Sent from the Haskell - Hugs-Users mailing list archive at Nabble.com. > > _______________________________________________ > Hugs-Users mailing list > Hugs-Users@haskell.org > http://www.haskell.org/mailman/listinfo/hugs-users > From ndmitchell at gmail.com Wed Apr 18 11:28:45 2007 From: ndmitchell at gmail.com (Neil Mitchell) Date: Wed Apr 18 11:26:48 2007 Subject: [Hugs-users] Constraint depth cut off Message-ID: <404396ef0704180828n5252d031q80c3bf29385527ef@mail.gmail.com> Hi I get the error message: ERROR - *** The type checker has reached the cutoff limit while trying to *** determine whether: *** Typeable (Foo Expr) *** can be deduced from: *** () *** This may indicate that the problem is undecidable. However, *** you may still try to increase the cutoff limit using the -c *** option and then try again. (The current setting is -c100) I find this surprising because in the same file I have: typename_Expr = mkTyCon "Expr" instance Typeable Expr where typeOf _ = mkTyConApp typename_Expr [] typename_Foo = mkTyCon "Foo" instance Typeable1 Foo where { typeOf1 _ = mkTyConApp typename_Foo [] } instance Typeable a => Typeable (Foo a) where { typeOf = typeOfDefault } I then went even further, giving it an explicit instance with: instance Typeable (Foo Expr) where And still I get the same error message. I originally had -c40 (default), but bumping it up has no effect. Any idea what may be causing this? Thanks Neil From ndmitchell at gmail.com Wed Apr 18 12:10:27 2007 From: ndmitchell at gmail.com (Neil Mitchell) Date: Wed Apr 18 12:08:31 2007 Subject: [Hugs-users] Re: Constraint depth cut off In-Reply-To: <404396ef0704180828n5252d031q80c3bf29385527ef@mail.gmail.com> References: <404396ef0704180828n5252d031q80c3bf29385527ef@mail.gmail.com> Message-ID: <404396ef0704180910i7729d73an6a82e775830e626f@mail.gmail.com> Hi I have now reduced this bug to a smallish test case: test :: T1 -> T1 test = test2 test2 :: C3 (T2 a) a => a -> a test2 = undefined data T1 = C1 deriving Show data T2 a = T2 a deriving Show class C1 a where class C2 a where class C3 a b where instance C1 T1 where instance C1 a => C1 (T2 a) where instance (C1 a, C2 a) => C3 T1 a where instance (C3 a (T2 a)) => C2 (T2 a) where instance (C2 (T2 a)) => C3 (T2 a) b where In Hugs I get (overlapping instances and unsafe overlapping instances turned on): *** The type checker has reached the cutoff limit while trying to *** determine whether: *** C1 T1 *** can be deduced from: *** () The explicit instance for this type makes it surprising that it fails to find an instance. In GHC with -fglasgow-exts -fallow-undecidable-instances, it works fine. Thanks Neil From alexteslin at yahoo.co.uk Wed Apr 18 16:19:52 2007 From: alexteslin at yahoo.co.uk (Alex Teslin) Date: Wed Apr 18 16:17:55 2007 Subject: [Hugs-users] isPrime definition Message-ID: <20070418201952.3262.qmail@web27312.mail.ukl.yahoo.com> Hi, I am a newbie in Haskell and have a trivial question. I am using Simon Thomson's textbook for learning Haskell with Hugs. I am stack with exer 5.10, which asks to define isPrime function using divisors function previously defined. I have managed to define the divisor function like this: divisors :: Int -> [Int] divisors n = [x | x<-[1..n], n `mod` x == 0] but when i am trying with isPrime function using divisors and list comprehension - i am lost because the type signature should be isPrime :: Int->Bool But any list comprehension generates a list, which is not what i want. Any suggestions please? Thank you --------------------------------- Yahoo! Answers - Got a question? Someone out there knows the answer. Tryit now. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/hugs-users/attachments/20070418/1209c8dd/attachment-0001.htm From mhills at cs.uiuc.edu Wed Apr 18 16:30:49 2007 From: mhills at cs.uiuc.edu (Mark Hills) Date: Wed Apr 18 16:29:44 2007 Subject: [Hugs-users] isPrime definition In-Reply-To: <20070418201952.3262.qmail@web27312.mail.ukl.yahoo.com> References: <20070418201952.3262.qmail@web27312.mail.ukl.yahoo.com> Message-ID: <46267FF9.9080702@cs.uiuc.edu> You could always do something like this: isPrime :: Int -> Bool isPrime n = if (n < 2) then False else if (length (divisors n)) == 2 then True else False If the number is prime, you will only have two divisors, 1 and the number, so you know it isn't prime if you don't have two divisors. Also, primes are defined as being > 1, so it's good to put that check in as well. Mark Alex Teslin wrote: > Hi, I am a newbie in Haskell and have a trivial question. > > I am using Simon Thomson's textbook for learning Haskell with Hugs. > I am stack with exer 5.10, which asks to define isPrime function using > divisors function previously defined. > > I have managed to define the divisor function like this: > > divisors :: Int -> [Int] > divisors n = [x | x<-[1..n], n `mod` x == 0] > > but when i am trying with isPrime function using divisors and list > comprehension - i am lost because the type signature should be isPrime > :: Int->Bool > > But any list comprehension generates a list, which is not what i want. > > Any suggestions please? > > Thank you > > ------------------------------------------------------------------------ > Yahoo! Answers - Got a question? Someone out there knows the answer. > Try it now > . > > ------------------------------------------------------------------------ > > _______________________________________________ > Hugs-Users mailing list > Hugs-Users@haskell.org > http://www.haskell.org/mailman/listinfo/hugs-users > From ross at soi.city.ac.uk Fri Apr 20 07:18:50 2007 From: ross at soi.city.ac.uk (Ross Paterson) Date: Fri Apr 20 07:16:49 2007 Subject: [Hugs-users] Re: Constraint depth cut off In-Reply-To: <404396ef0704180910i7729d73an6a82e775830e626f@mail.gmail.com> References: <404396ef0704180828n5252d031q80c3bf29385527ef@mail.gmail.com> <404396ef0704180910i7729d73an6a82e775830e626f@mail.gmail.com> Message-ID: <20070420111850.GA3786@soi.city.ac.uk> On Wed, Apr 18, 2007 at 05:10:27PM +0100, Neil Mitchell wrote: > I have now reduced this bug to a smallish test case: > > test :: T1 -> T1 > test = test2 > > test2 :: C3 (T2 a) a => a -> a > test2 = undefined > > data T1 = C1 deriving Show > data T2 a = T2 a deriving Show > > class C1 a where > class C2 a where > class C3 a b where > > instance C1 T1 where > instance C1 a => C1 (T2 a) where > instance (C1 a, C2 a) => C3 T1 a where > instance (C3 a (T2 a)) => C2 (T2 a) where > instance (C2 (T2 a)) => C3 (T2 a) b where > > In Hugs I get (overlapping instances and unsafe overlapping instances > turned on): > > *** The type checker has reached the cutoff limit while trying to > *** determine whether: > *** C1 T1 > *** can be deduced from: > *** () > > The explicit instance for this type makes it surprising that it fails > to find an instance. The error message is silly, but there really is a loop here: C3 (T2 T1) T1 <= C2 (T2 T1) <= C3 T1 (T2 T1) <= C2 (T2 T1) > In GHC with -fglasgow-exts -fallow-undecidable-instances, it works fine. That's because recent GHCs detect the loop when they get to an identical constraint, and declare the constraint solved. Simon calls this feature recursive dictionaries; Martin Sulzmann calls it co-induction. I can't find where it's documented in the GHC User's Guide, though. Hugs does not aim to duplicate that behaviour; the bug here is the error message. Here's a simpler illustration of it: class C a where f :: a -> a instance (Eq a, C a) => C a test = f True with -98 says it can't prove Eq Bool, when it should say C Bool. From ndmitchell at gmail.com Fri Apr 20 08:40:46 2007 From: ndmitchell at gmail.com (Neil Mitchell) Date: Fri Apr 20 08:38:43 2007 Subject: [Hugs-users] Re: Constraint depth cut off In-Reply-To: <20070420111850.GA3786@soi.city.ac.uk> References: <404396ef0704180828n5252d031q80c3bf29385527ef@mail.gmail.com> <404396ef0704180910i7729d73an6a82e775830e626f@mail.gmail.com> <20070420111850.GA3786@soi.city.ac.uk> Message-ID: <404396ef0704200540h306ce6b1idb480f7d610543b0@mail.gmail.com> Hi > The error message is silly, but there really is a loop here: > > C3 (T2 T1) T1 <= C2 (T2 T1) <= C3 T1 (T2 T1) <= C2 (T2 T1) > > > In GHC with -fglasgow-exts -fallow-undecidable-instances, it works fine. I was aware of the loop, but I was getting confused because the error message was pointing somewhere else. With the knowledge that the error message is wrong, and that loops are bad, I've managed to rewrite the code in which I was having problems, so its all happy now. Thanks very much! Neil