inferred-type

Haskell question about function

Working out of RWH, Chapter 3 question 5 requests I create a function to test for the existence of a paldindrome. I wrote this, but it doesn't work pCheck :: (Eq a) => [a] -> Bool; pCheck a = take n a == ( take n $ reverse a ) where n = floor ( length a / 2 ) I get this error when I try to run it: No instance for (RealFrac Int) ...

Why doesn't C# allow for global inferred types i.e. using var?

I know it can't be done since using var can only be done for local variables. I'm just wondering if anyone has a theory why the C# team thought this should be so. e.g. what would be wrong with this: public class SomeClass { var someString = "hello"; //not cool public SomeClass() { var someOtherString = "hello"; //coo...

Types in Haskell

I'm kind of new in Haskell and I have difficulty understanding how inferred types and such works. map :: (a -> b) -> [a] -> [b] (.) :: (a -> b) -> (c -> a) -> c -> b What EXACTLY does that mean? foldr :: (a -> b -> b) -> b -> [a] -> b foldl :: (a -> b -> a) -> a -> [b] -> a foldl1 :: (a -> a -> a) -> [a] -> a What are the differenc...

Help with possible Haskell type inference quiz questions

foldr:: (a -> b -> b) -> b -> [a] -> b map :: (a -> b) -> [a] -> [b] mys :: a -> a (.) :: (a -> b) -> (c -> a) -> c -> b what is inferred type of: a.map mys :: b.mys map :: c.foldr map :: d.foldr map.mys :: I've tried to create mys myself using mys n = n + 2 but the type of that is mys :: Num a => a -> a What's the difference bet...

Unboxing to unknown type

I'm trying to figure out syntax that supports unboxing an integral type (short/int/long) to its intrinsic type, when the type itself is unknown. Here is a completely contrived example that demonstrates the concept: // Just a simple container that returns values as objects struct DataStruct { public short ShortVale; public int In...

How can I refactor our the type parameter from this code?

I want to write an extension method that tests if an attribute is applied on a method call, and I'd like to specify the method as a lambda expression. Currently, I have the following (working) approach, but I really don't like the way this code looks: // Signature of my extension method: public static bool HasAttribute<TAttribute, TDele...