Implementing Semigroup for dependent pair in Idris -


i'm trying implement semigroup interface simple dependent pair in idris, doesn't compile :

semigroup (n ** vect n f)   (<+>) (_ ** xs) (_ ** ys) = (_ ** xs ++ ys) 

with error

type mismatch between     ty ,     nat 

but compile :

mypair:type -> type mypair f = (n ** vect n f)  semigroup (mypair f)    (<+>) (_ ** xs) (_ ** ys) = (_ ** xs ++ ys) 

why ? best way accomplish ?

idris faq:

if use name in type begins lower case letter, , not applied arguments, idris treat implicitly bound argument.

one approach solving problem rid of syntactic sugar , explicitly bind n this:

semigroup (dpair nat (\n => vect n f))   (<+>) = (_ ** xs) (_ ** ys) = (_ ** xs ++ ys) 

another approach use upper-case letter vector length:

semigroup (n ** vect n f)   (<+>) = (_ ** xs) (_ ** ys) = (_ ** xs ++ ys) 

here, n not bound in semigroup implementation, , allows dpair syntactic sugar kick in , bind n did in first variant.

as mypair example, compiles because example equivalent dpair example above. if remove sugar becomes clear:

mypair:type -> type mypair f = dpair nat (\n => vect n f) 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -