Comments (2)
I think you might be over-complicating the problem a bit. Here are three ways you could write your length
functions, none of which require the use of eliminators:
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeInType #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -Wall #-}
{-# OPTIONS_GHC -Wno-unticked-promoted-constructors #-}
module Bug where
import Data.Kind
import Data.Singletons.Prelude
import Data.Singletons.Prelude.List
import Data.Singletons.TypeLits
data HList :: [Type] -> Type where
HNil :: HList '[]
(:&:) :: t -> HList ts -> HList (t:ts)
infixr 5 :&:
length1 :: SingI (Length ts) => HList ts -> Sing (Length ts)
length1 _ = sing
length2 :: forall (ts :: [Type]). SingI ts => HList ts -> Sing (Length ts)
length2 _ = sLength (sing @_ @ts)
length3 :: HList ts -> Sing (Length ts)
length3 HNil = SNat @0
length3 (_ :&: xs) = SNat @1 %:+ length3 xs
length3
could, conceivably, be rewritten to use an eliminator over HList
s, but that would first require writing Sing
/SingKind
instances for HList
and, well, doing so isn't pretty. So I'd avoid that if possible.
from eliminators.
ah ok, that's enlightening 🙂
Edit: length3
is what I want.
from eliminators.
Related Issues (7)
- Generate eliminators using Template Haskell
- Should we bother generating eliminators with predicates of kind (<Datatype> -> Type)? HOT 1
- Unable to proof per Induction over Nat with Lists HOT 14
- Eliminators and Typeclasses HOT 17
- Emulate Coq's induction schemes for data types that inhabit Prop
- Add eliminator for `Symbol`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eliminators.