Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Testing for congruence in Haskell

Name: Anonymous 2008-12-06 14:08

Hello /prog/ Haskell programers users. Is it possible to test for the congruence of expression in Haskell? I know i can say
this a = if (a 12) == 12 then (a 12) else (a 13)
and expect this (\ x -> x + 1) to eval to 14. But is there anyway to test for the equivalence of two (or more) expressons without actually applying either of them? In other words, can haskell do anything with thunks, aide from than apply them?

(\ x -> x) == (\ x -> x) is not an expression. Is there a corrext syntax for this type of thing?
Thanks,

Name: Anonymous 2008-12-06 14:12

Use Nomads.

Name: Anonymous 2008-12-06 14:53

You might be able to do that with Template Haskell.

Name: Anonymous 2008-12-06 14:57

I don't think so, you're not even supposed to know about existence of thunks.

Name: Anonymous 2008-12-06 15:25

There is no way to know in general if two programs compute the same function.  This is because not all programs actually halt and give an answer and there is no way to know before hand if a program is in that class.  Since there is no way (in general) to know what a program will output without actually running it there is no way to tell if two programs are equivalent.

Not only that, but programs could have infinite domains meaning in order to know they are equivalent you'd have to compare an infinite amount of outputs.

The only way this could possibly work is if you limited your notion of "expressions" to something less than Turing complete and if you only wanted to assert equivalence over a limited domain.

TL;DR no, but maybe if you limited what you actually want.

Name: Anonymous 2008-12-06 15:50

>>5
Since there is no way (in general) to know what a program will output without actually running it there is no way to tell if two programs are equivalent.
Sure, maybe we can't know for sure, but we can make a pretty good guess. If we see a "for" loops that runs 100,000 times, there's a good chance that the program is in an infinite loop.

Name: Anonymous 2008-12-06 15:53

The combined powers of SICP can't solve the halting problem?  What a waste of time!

Name: Anonymous 2008-12-06 15:58

You might be a worthless nigger for using haskell.

Name: Anonymous 2008-12-06 16:16

>>8
amIANigger :: Maybe Nigger -> Nothing

Name: Anonymous 2008-12-06 16:58

>>6
Listen, I've heard this before, but for every program you write to determine that a program will halt without actually running it, I can trivially write a program that will crash your program.

Name: Anonymous 2008-12-06 17:10

>>10
Steve Jobs!?

Name: Anonymous 2008-12-06 17:13

>>11
More like Steve Tasks

Name: Anonymous 2008-12-06 17:40

1. Why can I not do (Just 1) >>= succ? How do I get the value out of the Maybe monad?

2. getDirectoryContents "/" >>= return . filter (`notElem` [".", ".."]) What is the point of the >>= return?

Thank you Haskell wizards ^0^

Name: Anonymous 2008-12-06 18:27

>>13
Enjoy your static typing. Also fromJust.

Name: Anonymous 2008-12-06 18:47

>>13
Regular datatypes are not fuqin nomads.

Name: Anonymous 2008-12-06 18:52

>>15
How do I get value out of Just?
How do I get String from keyboard out of IO String?

Name: Anonymous 2008-12-06 18:55

>>13
What you probably want there is fmap succ (Just 1), though Just 1 >>= return . succ would also work. The function argument to >>= must return a value in the monad, but fmap's does not. Thus, to run a pure function on the value(s) in the monad, we can compose it with return :: b -> m b. Compare:
(>>=) :: Monad m => m a -> (a -> m b) -> m b
fmap :: Functor f => (a -> b) -> f a -> f b


In a monad, it is also possible to use liftM. liftM is different because it requires a monad, not a functor, even though it does the same thing, and also there are versions for other argument counts: liftM2, liftM3, etc. We could also use liftM2 (+) (Just 1) (Just 1).

For the second question we could also use filter (`notElem` [".", ".."]) `fmap` getDirectoryContents "/".

To get the value out of the Maybe monad, use fromJust or maybe.

Name: Anonymous 2008-12-06 19:08

>>17
Thanks. So why does >>= have to return a value inside of a monad? Just so you can chain them?

Name: Anonymous 2008-12-06 19:35

>>18
In the case of IO and other monads, it allows chaining, yes. (You couldn't do getDirectoryContents "/" >>= mapM_ putStrLn with fmap/liftM because the lifted function is pure.)

In the case of Maybe, it's still more useful than fmap because you can not only change the values inside the box (like fmap does), but also the type of the box: Just 1 >>= const Nothing. You can transform a Right 1 to a Left "Error!", and so on.

Name: Anonymous 2008-12-06 19:57

>>18
In the case of the Maybe monad, because >>= may return Nothing and STATIC TYPING JUST KICKED IN YO.

In general, because that's how the type of >>= is constrained ( (>>=) :: m a -> (a -> m b) -> m b ).

Name: Anonymous 2008-12-07 13:27

Fuck all you idiots
Go back to #haskell
THIS IS /PROG/

Name: Anonymous 2008-12-07 16:28

loeb :: Functor f => f (f a -> a) -> f a
loeb f = fmap ($ loeb f) f

Name: Anonymous 2008-12-07 16:35

>>21
Read SICP

Name: Anonymous 2010-12-17 1:29

Are you GAY?
Are you a NIGGER?
Are you a GAY NIGGER?

If you answered "Yes" to all of the above questions, then GNAA (GAY NIGGER ASSOCIATION OF AMERICA) might be exactly what you've been looking for!

Don't change these.
Name: Email:
Entire Thread Thread List