type-signature

The type signature of a combinator does not match the type signature of its equivalent Lambda function

ⅰ亾dé卋堺 提交于 2019-12-07 04:17:48
问题 Consider this combinator: S (S K) Apply it to the arguments X Y: S (S K) X Y It contracts to: X Y I converted S (S K) to the corresponding Lambda terms and got this result: (\x y -> x y) I used the Haskell WinGHCi tool to get the type signature of (\x y -> x y) and it returned: (t1 -> t) -> t1 -> t That makes sense to me. Next, I used WinGHCi to get the type signature of s (s k) and it returned: ((t -> t1) -> t) -> (t -> t1) -> t That doesn't make sense to me. Why are the type signatures

The type signature of a combinator does not match the type signature of its equivalent Lambda function

你说的曾经没有我的故事 提交于 2019-12-05 10:42:44
Consider this combinator: S (S K) Apply it to the arguments X Y: S (S K) X Y It contracts to: X Y I converted S (S K) to the corresponding Lambda terms and got this result: (\x y -> x y) I used the Haskell WinGHCi tool to get the type signature of (\x y -> x y) and it returned: (t1 -> t) -> t1 -> t That makes sense to me. Next, I used WinGHCi to get the type signature of s (s k) and it returned: ((t -> t1) -> t) -> (t -> t1) -> t That doesn't make sense to me. Why are the type signatures different? Note: I defined s, k, and i as: s = (\f g x -> f x (g x)) k = (\a x -> a) i = (\f -> f) We start

Haskell type signature with multiple class constraints

只愿长相守 提交于 2019-12-04 15:20:27
问题 How can I have multiple class constraints, so if A is an Eq and B is a Num , I could say either f :: Eq a => a -> b` or f :: Num b => a -> b So, how can I have Eq a => and Num b => at the same time? f :: Eq a => Num b => a -> b , f :: Eq a -> Num b => a -> b , and f :: Eq a, Num b => a -> b didn't do what I wanted. 回答1: They're usually called class constraints , as Eq and Num are called type-classes. How about this? f :: (Eq a, Num b) => a -> b The parentheses are significant. 来源: https:/

What's going on in this type signature? (Vector.Mutable modifiers in Haskell)

纵饮孤独 提交于 2019-12-04 02:12:08
Mutable vectors in Haskell have three element-level mutators: read :: PrimMonad m => MVector (PrimState m) a -> Int -> m a write :: PrimMonad m => MVector (PrimState m) a -> Int -> a -> m () swap :: PrimMonad m => MVector (PrimState m) a -> Int -> Int -> m () Now I can use these fine -- import Data.Vector import Data.Vector.Mutable import Control.Monad.ST import Control.Monad.Primitive incrAt :: Vector Double -> Int -> Vector Double incrAt vec i = runST $ do mvec <- thaw vec oldval <- read mvec i write mvec i (oldval + 1) freeze mvec But what is going on here? What is a PrimMonad ? And is

Overloading function signatures haskell

断了今生、忘了曾经 提交于 2019-12-03 04:35:44
I get the following error message when I compile: Duplicate type signature: weightedMedian.hs:71:0-39: findVal :: [ValPair] -> Double -> Double weightedMedian.hs:68:0-36: findVal :: [ValPair] -> Int -> Double My solution is to have findValI and findValD. However, findValI just converts the Int type to a Double and calls findValD. Also I can't pattern match on types of Num (Int, Double) so I can't just change the type signature to findVal :: [ValPair] -> Num -> Double In many languages I wouldn't need different names. Why do I need different names in Haskell? Would this be hard to add to the

What does # (pound sign) mean in type signatures?

牧云@^-^@ 提交于 2019-11-30 11:17:50
What does # mean in type signatures like seq<#seq<'a>> compared to just seq<seq<'a>> ? This is called flexible type . The short summary is that #type means any type that is inherited from type . So, in your concrete example seq<#seq<'a>> will be a sequence of any collections containing 'a values. When calling a function, F# automatically casts concrete types to interfaces - so for example, you can call a function taking seq<'a> with array 'a[] as an argument. However, this does not work when you have array of arrays - because 'a[][] only implements seq<'a[]> but not seq<seq<'a>> . For example,

What does # (pound sign) mean in type signatures?

家住魔仙堡 提交于 2019-11-29 16:58:11
问题 What does # mean in type signatures like seq<#seq<'a>> compared to just seq<seq<'a>> ? 回答1: This is called flexible type . The short summary is that #type means any type that is inherited from type . So, in your concrete example seq<#seq<'a>> will be a sequence of any collections containing 'a values. When calling a function, F# automatically casts concrete types to interfaces - so for example, you can call a function taking seq<'a> with array 'a[] as an argument. However, this does not work

Type error when testing a function with a negative number

末鹿安然 提交于 2019-11-29 16:07:04
I am following along with the Learn you a Haskell for great good , I have implemented take' : take' :: (Ord i, Num i) => i -> [a] -> [a] take' n _ | n <= 0 = [] take' _ [] = [] take' n (x:xs) = x: take' (n-1) xs When testing the function with: take' -2 [2] instead of getting an empty list, I have this message: Non type-variable argument in the constraint: Num (i -> [a] -> [a]) (Use FlexibleContexts to permit this) When checking that ‘it’ has the inferred type it :: forall i a t. (Num i, Num t, Num (i -> [a] -> [a]), Num ([t] -> i -> [a] -> [a]), Ord i) => i -> [a] -> [a] I have added a space

Using Haskell's “Maybe”, type declarations [beginner's question]

ⅰ亾dé卋堺 提交于 2019-11-29 10:43:51
I've started experimenting with Haskell and have a problem. qqq is a function that should print one string if called with "Nothing" and print other things if called with "Just something". The first attempt seems like working: qqq Nothing = print "There isn't anything to be printed." qqq (Just x) = print "There is something to be printed." >> print x main :: IO () main = qqq (Just 43) But: when I try to make main = qqq (Nothing) it fails ("Ambiguous type variable `a0' in the constraint: (Show a0) arising from a use of 'qqq'") When I want to add type signature if fails: qqq :: Maybe x => x -> IO

Using Haskell's “Maybe”, type declarations [beginner's question]

故事扮演 提交于 2019-11-28 03:58:30
问题 I've started experimenting with Haskell and have a problem. qqq is a function that should print one string if called with "Nothing" and print other things if called with "Just something". The first attempt seems like working: qqq Nothing = print "There isn't anything to be printed." qqq (Just x) = print "There is something to be printed." >> print x main :: IO () main = qqq (Just 43) But: when I try to make main = qqq (Nothing) it fails ("Ambiguous type variable `a0' in the constraint: (Show