partial-functions

Idris: function works with Nat parameter and fails type checking with Integer parameter

别说谁变了你拦得住时间么 提交于 2019-12-31 04:10:28
问题 I am new to Idris. I am experimenting with types and my task is to make an "onion": a function that takes two arguments: a number and whatever and puts whatever into List nested such number of times. For example, the result for mkOnion 3 "Hello World" should be [[["Hello World"]]] . I've made such a function, this is my code: onionListType : Nat -> Type -> Type onionListType Z b = b onionListType (S a) b = onionListType a (List b) mkOnionList : (x : Nat) -> y -> onionListType x y mkOnionList

In Haskell, why non-exhaustive patterns are not compile-time errors?

时间秒杀一切 提交于 2019-12-28 16:30:13
问题 This is a follow-up of Why am I getting "Non-exhaustive patterns in function..." when I invoke my Haskell substring function? I understand that using -Wall , GHC can warn against non-exhaustive patterns. I'm wondering what's the reason behind not making it a compile-time error by default given that it's always possible to explicitly define a partial function: f :: [a] -> [b] -> Int f [] _ = error "undefined for empty array" f _ [] = error "undefined for empty array" f (_:xs) (_:ys) = length

Anonymous PartialFunction syntax

妖精的绣舞 提交于 2019-12-12 11:47:03
问题 I asked this question earlier: Combine a PartialFunction with a regular function and then realized, that I haven't actually asked it right. So, here goes another attempt. If I do this: val foo = PartialFunction[Int, String] { case 1 => "foo" } val bar = foo orElse { case x => x.toString } it does not compile: error: missing parameter type for expanded function The argument types of an anonymous function must be fully known. (SLS 8.5) Expected type was: PartialFunction[?,?] But this works fine

Anonymous partial function in early initializer requires “premature access to class”

妖精的绣舞 提交于 2019-12-02 03:57:54
问题 Why does this fail to compile: trait Item trait StringItem extends Item { def makeString: String } trait SomeOtherItem extends Item trait DummyTrait case class Marquee(items: Seq[Item]) extends { val strings: Seq[String] = items.collect { case si: StringItem => si.makeString // <-- partial function inside braces } } with DummyTrait with the error message <$anon: Item => String> requires premature access to class Marquee ? It seems to me that the partial function makes no use of Marquee . Yet

Anonymous partial function in early initializer requires “premature access to class”

别来无恙 提交于 2019-12-02 01:27:06
Why does this fail to compile: trait Item trait StringItem extends Item { def makeString: String } trait SomeOtherItem extends Item trait DummyTrait case class Marquee(items: Seq[Item]) extends { val strings: Seq[String] = items.collect { case si: StringItem => si.makeString // <-- partial function inside braces } } with DummyTrait with the error message <$anon: Item => String> requires premature access to class Marquee ? It seems to me that the partial function makes no use of Marquee . Yet this compiles: val pf: PartialFunction[Item, String] = { case si: StringItem => si.makeString } case

In Haskell, why non-exhaustive patterns are not compile-time errors?

心已入冬 提交于 2019-11-28 10:41:39
This is a follow-up of Why am I getting "Non-exhaustive patterns in function..." when I invoke my Haskell substring function? I understand that using -Wall , GHC can warn against non-exhaustive patterns. I'm wondering what's the reason behind not making it a compile-time error by default given that it's always possible to explicitly define a partial function: f :: [a] -> [b] -> Int f [] _ = error "undefined for empty array" f _ [] = error "undefined for empty array" f (_:xs) (_:ys) = length xs + length ys The question is not GHC-specific. Is it because... nobody wanted to enforce a Haskell