final Button button2 = (Button) findViewById(R.id.senddirect);
button2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent("com.twidroid.SendDirect");
/* set recipient of direct message */
intent.putExtra("com.twidroid.extra.TO",
"androidev");
/* set direct message content */
intent.putExtra("com.twidroid.extra.MESSAGE",
"This is a test from Twidroid public intent.");
try {
startActivityForResult(intent, 1);
} catch (ActivityNotFoundException e) {
/* Handle Exception if Twidroid is not installed */
TextView text = (TextView) findViewById(R.id.message);
text.setText("Twidroid Application not found.");
button2.setVisibility(View.GONE);
}
}
});
-- Uasge
*Main> let antwords = words "the tan ant gets some fat"
*Main> clusterBy length antwords
[["the","tan","ant","fat"],["gets","some"]]
*Main> clusterBy head antwords
[["ant"],["fat"],["gets"],["some"],["the","tan"]]
*Main> clusterBy last antwords
[["the","some"],["tan"],["gets"],["ant","fat"]]
-- Source
import Control.Arrow ((&&&))
import qualified Data.Map as M
clusterBy :: Ord b => (a -> b) -> [a] -> [[a]]
clusterBy f = M.elems . M.map reverse . M.fromListWith (++) . map (f &&& return)
-- Enabling the extension
{-# OPTIONS -fglasgow-exts #-}
-- Equal like class
class MEEq a where
(=-=) :: a -> a -> Bool
-- Instances with no implementation
instance MEEq ()
instance MEEq Bool
instance MEEq Int
-- The rewrite rule
{-# RULES
"eq/Bool" (=-=) = eq_Bool :: Bool -> Bool -> Bool
"eq/Unit" (=-=) = eq_Unit :: () -> () -> Bool
#-}
main = do
print $ True =-= False
print $ () =-= ()
-- This fails (at runtime!) since we didn't define a rule for it
print $ 7 =-= (8 :: Int)
-- Makes sure to fail any instance that doesn't have an implementation on compile time
{-# RULES
"Unable to resolve instance resolution" (=-=) = (=-=)
#-}