Skip to main content

New answers tagged

1 vote

Why explicitly writing a singleton ctor - instead of just _ - is necessary in the context of dependent types?

You haven't really fleshed out your proposal for what this new GHC capability would look like. Are you imagining that GHC would, in the (very!) special case that an ADT or GADT has a single, zero-...
K. A. Buhr's user avatar
  • 52.8k
1 vote

Church encoding (lambda calculus) to define < , > , !=

The usual lambda calculus (from now on: LC) way to encode numbers is indeed the Church encoding: 0 = λf. λx. x 1 = λf. λx. f x 2 = λf. λx. f (f x) This notation can be cumbersome to use, though. We ...
Will Ness's user avatar
  • 71.6k
2 votes

Is there a feature (pattern synonyms?) to turn a datatype into syntactic sugar for constructing another datatype?

Probably the best you can do with existing technology is to simply convert the pattern match to a runtime error -- rather than a compile-time error. Like this: data Bar = Bar (Bool -> Int -> ...
Daniel Wagner's user avatar
2 votes

Is there a feature (pattern synonyms?) to turn a datatype into syntactic sugar for constructing another datatype?

To show that sometimes what you ask for is not what you want ... here's a 'solution': {-# LANGUAGE PatternSynonyms, ViewPatterns #-} type Foo = (String, String, String, String) -- override the data ...
AntC's user avatar
  • 2,846
1 vote

How can I implement consistent typed error propagation in C# without scattering try/catch across layers?

Both approaches are fine, only if you have Result-type return, you handle the error internally Result public Result<User> GetUser(int id) { try { var user = _repo.Find(id); ...
T.S.'s user avatar
  • 19.7k

Top 50 recent answers are included